add proper email addresses to the comment headers
[openwrt.git] / target / linux / generic-2.6 / patches / 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 @@ -1371,6 +1371,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 @@ -68,6 +68,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,2124 @@
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 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2187 + SLAB_CTOR_CONSTRUCTOR)
2188 + inode_init_once(&ei->vfs_inode);
2189 +}
2190 +
2191 +
2192 +static int __init init_inodecache(void)
2193 +{
2194 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2195 + sizeof(struct squashfs_inode_info),
2196 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2197 + init_once, NULL);
2198 + if (squashfs_inode_cachep == NULL)
2199 + return -ENOMEM;
2200 + return 0;
2201 +}
2202 +
2203 +
2204 +static void destroy_inodecache(void)
2205 +{
2206 + kmem_cache_destroy(squashfs_inode_cachep);
2207 +}
2208 +
2209 +
2210 +module_init(init_squashfs_fs);
2211 +module_exit(exit_squashfs_fs);
2212 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2213 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2214 +MODULE_LICENSE("GPL");
2215 diff -urN linux-2.6.21.1.old/fs/squashfs/Makefile linux-2.6.21.1.dev/fs/squashfs/Makefile
2216 --- linux-2.6.21.1.old/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2217 +++ linux-2.6.21.1.dev/fs/squashfs/Makefile 2007-05-26 19:00:37.123351456 +0200
2218 @@ -0,0 +1,7 @@
2219 +#
2220 +# Makefile for the linux squashfs routines.
2221 +#
2222 +
2223 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2224 +squashfs-y += inode.o
2225 +squashfs-y += squashfs2_0.o
2226 diff -urN linux-2.6.21.1.old/fs/squashfs/squashfs2_0.c linux-2.6.21.1.dev/fs/squashfs/squashfs2_0.c
2227 --- linux-2.6.21.1.old/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2228 +++ linux-2.6.21.1.dev/fs/squashfs/squashfs2_0.c 2007-05-26 19:00:37.125351152 +0200
2229 @@ -0,0 +1,758 @@
2230 +/*
2231 + * Squashfs - a compressed read only filesystem for Linux
2232 + *
2233 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2234 + * Phillip Lougher <phillip@lougher.org.uk>
2235 + *
2236 + * This program is free software; you can redistribute it and/or
2237 + * modify it under the terms of the GNU General Public License
2238 + * as published by the Free Software Foundation; either version 2,
2239 + * or (at your option) any later version.
2240 + *
2241 + * This program is distributed in the hope that it will be useful,
2242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2244 + * GNU General Public License for more details.
2245 + *
2246 + * You should have received a copy of the GNU General Public License
2247 + * along with this program; if not, write to the Free Software
2248 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2249 + *
2250 + * squashfs2_0.c
2251 + */
2252 +
2253 +#include <linux/types.h>
2254 +#include <linux/squashfs_fs.h>
2255 +#include <linux/module.h>
2256 +#include <linux/errno.h>
2257 +#include <linux/slab.h>
2258 +#include <linux/fs.h>
2259 +#include <linux/smp_lock.h>
2260 +#include <linux/slab.h>
2261 +#include <linux/squashfs_fs_sb.h>
2262 +#include <linux/squashfs_fs_i.h>
2263 +#include <linux/buffer_head.h>
2264 +#include <linux/vfs.h>
2265 +#include <linux/init.h>
2266 +#include <linux/dcache.h>
2267 +#include <linux/wait.h>
2268 +#include <linux/zlib.h>
2269 +#include <linux/blkdev.h>
2270 +#include <linux/vmalloc.h>
2271 +#include <asm/uaccess.h>
2272 +#include <asm/semaphore.h>
2273 +
2274 +#include "squashfs.h"
2275 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2276 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2277 + struct nameidata *);
2278 +
2279 +static struct file_operations squashfs_dir_ops_2 = {
2280 + .read = generic_read_dir,
2281 + .readdir = squashfs_readdir_2
2282 +};
2283 +
2284 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2285 + .lookup = squashfs_lookup_2
2286 +};
2287 +
2288 +static unsigned char squashfs_filetype_table[] = {
2289 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2290 +};
2291 +
2292 +static int read_fragment_index_table_2(struct super_block *s)
2293 +{
2294 + struct squashfs_sb_info *msblk = s->s_fs_info;
2295 + struct squashfs_super_block *sblk = &msblk->sblk;
2296 +
2297 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2298 + (sblk->fragments), GFP_KERNEL))) {
2299 + ERROR("Failed to allocate uid/gid table\n");
2300 + return 0;
2301 + }
2302 +
2303 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2304 + !squashfs_read_data(s, (char *)
2305 + msblk->fragment_index_2,
2306 + sblk->fragment_table_start,
2307 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2308 + (sblk->fragments) |
2309 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2310 + ERROR("unable to read fragment index table\n");
2311 + return 0;
2312 + }
2313 +
2314 + if (msblk->swap) {
2315 + int i;
2316 + unsigned int fragment;
2317 +
2318 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2319 + i++) {
2320 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2321 + &msblk->fragment_index_2[i], 1);
2322 + msblk->fragment_index_2[i] = fragment;
2323 + }
2324 + }
2325 +
2326 + return 1;
2327 +}
2328 +
2329 +
2330 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2331 + long long *fragment_start_block,
2332 + unsigned int *fragment_size)
2333 +{
2334 + struct squashfs_sb_info *msblk = s->s_fs_info;
2335 + long long start_block =
2336 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2337 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2338 + struct squashfs_fragment_entry_2 fragment_entry;
2339 +
2340 + if (msblk->swap) {
2341 + struct squashfs_fragment_entry_2 sfragment_entry;
2342 +
2343 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2344 + start_block, offset,
2345 + sizeof(sfragment_entry), &start_block,
2346 + &offset))
2347 + goto out;
2348 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2349 + } else
2350 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2351 + start_block, offset,
2352 + sizeof(fragment_entry), &start_block,
2353 + &offset))
2354 + goto out;
2355 +
2356 + *fragment_start_block = fragment_entry.start_block;
2357 + *fragment_size = fragment_entry.size;
2358 +
2359 + return 1;
2360 +
2361 +out:
2362 + return 0;
2363 +}
2364 +
2365 +
2366 +static struct inode *squashfs_new_inode(struct super_block *s,
2367 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2368 +{
2369 + struct squashfs_sb_info *msblk = s->s_fs_info;
2370 + struct squashfs_super_block *sblk = &msblk->sblk;
2371 + struct inode *i = new_inode(s);
2372 +
2373 + if (i) {
2374 + i->i_ino = ino;
2375 + i->i_mtime.tv_sec = sblk->mkfs_time;
2376 + i->i_atime.tv_sec = sblk->mkfs_time;
2377 + i->i_ctime.tv_sec = sblk->mkfs_time;
2378 + i->i_uid = msblk->uid[inodeb->uid];
2379 + i->i_mode = inodeb->mode;
2380 + i->i_nlink = 1;
2381 + i->i_size = 0;
2382 + if (inodeb->guid == SQUASHFS_GUIDS)
2383 + i->i_gid = i->i_uid;
2384 + else
2385 + i->i_gid = msblk->guid[inodeb->guid];
2386 + }
2387 +
2388 + return i;
2389 +}
2390 +
2391 +
2392 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2393 +{
2394 + struct inode *i;
2395 + struct squashfs_sb_info *msblk = s->s_fs_info;
2396 + struct squashfs_super_block *sblk = &msblk->sblk;
2397 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2398 + sblk->inode_table_start;
2399 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2400 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2401 + - sblk->inode_table_start, offset);
2402 + long long next_block;
2403 + unsigned int next_offset;
2404 + union squashfs_inode_header_2 id, sid;
2405 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2406 + *sinodeb = &sid.base;
2407 +
2408 + TRACE("Entered squashfs_iget\n");
2409 +
2410 + if (msblk->swap) {
2411 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2412 + offset, sizeof(*sinodeb), &next_block,
2413 + &next_offset))
2414 + goto failed_read;
2415 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2416 + sizeof(*sinodeb));
2417 + } else
2418 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2419 + offset, sizeof(*inodeb), &next_block,
2420 + &next_offset))
2421 + goto failed_read;
2422 +
2423 + switch(inodeb->inode_type) {
2424 + case SQUASHFS_FILE_TYPE: {
2425 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2426 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2427 + long long frag_blk;
2428 + unsigned int frag_size;
2429 +
2430 + if (msblk->swap) {
2431 + if (!squashfs_get_cached_block(s, (char *)
2432 + sinodep, block, offset,
2433 + sizeof(*sinodep), &next_block,
2434 + &next_offset))
2435 + goto failed_read;
2436 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2437 + } else
2438 + if (!squashfs_get_cached_block(s, (char *)
2439 + inodep, block, offset,
2440 + sizeof(*inodep), &next_block,
2441 + &next_offset))
2442 + goto failed_read;
2443 +
2444 + frag_blk = SQUASHFS_INVALID_BLK;
2445 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2446 + !get_fragment_location_2(s,
2447 + inodep->fragment, &frag_blk, &frag_size))
2448 + goto failed_read;
2449 +
2450 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2451 + goto failed_read1;
2452 +
2453 + i->i_size = inodep->file_size;
2454 + i->i_fop = &generic_ro_fops;
2455 + i->i_mode |= S_IFREG;
2456 + i->i_mtime.tv_sec = inodep->mtime;
2457 + i->i_atime.tv_sec = inodep->mtime;
2458 + i->i_ctime.tv_sec = inodep->mtime;
2459 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2460 + i->i_blksize = PAGE_CACHE_SIZE;
2461 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2462 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2463 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2464 + SQUASHFS_I(i)->start_block = inodep->start_block;
2465 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2466 + SQUASHFS_I(i)->offset = next_offset;
2467 + if (sblk->block_size > 4096)
2468 + i->i_data.a_ops = &squashfs_aops;
2469 + else
2470 + i->i_data.a_ops = &squashfs_aops_4K;
2471 +
2472 + TRACE("File inode %x:%x, start_block %x, "
2473 + "block_list_start %llx, offset %x\n",
2474 + SQUASHFS_INODE_BLK(inode), offset,
2475 + inodep->start_block, next_block,
2476 + next_offset);
2477 + break;
2478 + }
2479 + case SQUASHFS_DIR_TYPE: {
2480 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2481 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2482 +
2483 + if (msblk->swap) {
2484 + if (!squashfs_get_cached_block(s, (char *)
2485 + sinodep, block, offset,
2486 + sizeof(*sinodep), &next_block,
2487 + &next_offset))
2488 + goto failed_read;
2489 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2490 + } else
2491 + if (!squashfs_get_cached_block(s, (char *)
2492 + inodep, block, offset,
2493 + sizeof(*inodep), &next_block,
2494 + &next_offset))
2495 + goto failed_read;
2496 +
2497 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2498 + goto failed_read1;
2499 +
2500 + i->i_size = inodep->file_size;
2501 + i->i_op = &squashfs_dir_inode_ops_2;
2502 + i->i_fop = &squashfs_dir_ops_2;
2503 + i->i_mode |= S_IFDIR;
2504 + i->i_mtime.tv_sec = inodep->mtime;
2505 + i->i_atime.tv_sec = inodep->mtime;
2506 + i->i_ctime.tv_sec = inodep->mtime;
2507 + SQUASHFS_I(i)->start_block = inodep->start_block;
2508 + SQUASHFS_I(i)->offset = inodep->offset;
2509 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2510 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2511 +
2512 + TRACE("Directory inode %x:%x, start_block %x, offset "
2513 + "%x\n", SQUASHFS_INODE_BLK(inode),
2514 + offset, inodep->start_block,
2515 + inodep->offset);
2516 + break;
2517 + }
2518 + case SQUASHFS_LDIR_TYPE: {
2519 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2520 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2521 +
2522 + if (msblk->swap) {
2523 + if (!squashfs_get_cached_block(s, (char *)
2524 + sinodep, block, offset,
2525 + sizeof(*sinodep), &next_block,
2526 + &next_offset))
2527 + goto failed_read;
2528 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2529 + sinodep);
2530 + } else
2531 + if (!squashfs_get_cached_block(s, (char *)
2532 + inodep, block, offset,
2533 + sizeof(*inodep), &next_block,
2534 + &next_offset))
2535 + goto failed_read;
2536 +
2537 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2538 + goto failed_read1;
2539 +
2540 + i->i_size = inodep->file_size;
2541 + i->i_op = &squashfs_dir_inode_ops_2;
2542 + i->i_fop = &squashfs_dir_ops_2;
2543 + i->i_mode |= S_IFDIR;
2544 + i->i_mtime.tv_sec = inodep->mtime;
2545 + i->i_atime.tv_sec = inodep->mtime;
2546 + i->i_ctime.tv_sec = inodep->mtime;
2547 + SQUASHFS_I(i)->start_block = inodep->start_block;
2548 + SQUASHFS_I(i)->offset = inodep->offset;
2549 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2550 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2551 + next_offset;
2552 + SQUASHFS_I(i)->u.s2.directory_index_count =
2553 + inodep->i_count;
2554 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2555 +
2556 + TRACE("Long directory inode %x:%x, start_block %x, "
2557 + "offset %x\n",
2558 + SQUASHFS_INODE_BLK(inode), offset,
2559 + inodep->start_block, inodep->offset);
2560 + break;
2561 + }
2562 + case SQUASHFS_SYMLINK_TYPE: {
2563 + struct squashfs_symlink_inode_header_2 *inodep =
2564 + &id.symlink;
2565 + struct squashfs_symlink_inode_header_2 *sinodep =
2566 + &sid.symlink;
2567 +
2568 + if (msblk->swap) {
2569 + if (!squashfs_get_cached_block(s, (char *)
2570 + sinodep, block, offset,
2571 + sizeof(*sinodep), &next_block,
2572 + &next_offset))
2573 + goto failed_read;
2574 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2575 + sinodep);
2576 + } else
2577 + if (!squashfs_get_cached_block(s, (char *)
2578 + inodep, block, offset,
2579 + sizeof(*inodep), &next_block,
2580 + &next_offset))
2581 + goto failed_read;
2582 +
2583 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2584 + goto failed_read1;
2585 +
2586 + i->i_size = inodep->symlink_size;
2587 + i->i_op = &page_symlink_inode_operations;
2588 + i->i_data.a_ops = &squashfs_symlink_aops;
2589 + i->i_mode |= S_IFLNK;
2590 + SQUASHFS_I(i)->start_block = next_block;
2591 + SQUASHFS_I(i)->offset = next_offset;
2592 +
2593 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2594 + "offset %x\n",
2595 + SQUASHFS_INODE_BLK(inode), offset,
2596 + next_block, next_offset);
2597 + break;
2598 + }
2599 + case SQUASHFS_BLKDEV_TYPE:
2600 + case SQUASHFS_CHRDEV_TYPE: {
2601 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2602 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2603 +
2604 + if (msblk->swap) {
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + sinodep, block, offset,
2607 + sizeof(*sinodep), &next_block,
2608 + &next_offset))
2609 + goto failed_read;
2610 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2611 + } else
2612 + if (!squashfs_get_cached_block(s, (char *)
2613 + inodep, block, offset,
2614 + sizeof(*inodep), &next_block,
2615 + &next_offset))
2616 + goto failed_read;
2617 +
2618 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2619 + goto failed_read1;
2620 +
2621 + i->i_mode |= (inodeb->inode_type ==
2622 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2623 + S_IFBLK;
2624 + init_special_inode(i, i->i_mode,
2625 + old_decode_dev(inodep->rdev));
2626 +
2627 + TRACE("Device inode %x:%x, rdev %x\n",
2628 + SQUASHFS_INODE_BLK(inode), offset,
2629 + inodep->rdev);
2630 + break;
2631 + }
2632 + case SQUASHFS_FIFO_TYPE:
2633 + case SQUASHFS_SOCKET_TYPE: {
2634 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2635 + goto failed_read1;
2636 +
2637 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2638 + ? S_IFIFO : S_IFSOCK;
2639 + init_special_inode(i, i->i_mode, 0);
2640 + break;
2641 + }
2642 + default:
2643 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2644 + inodeb->inode_type);
2645 + goto failed_read1;
2646 + }
2647 +
2648 + insert_inode_hash(i);
2649 + return i;
2650 +
2651 +failed_read:
2652 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2653 +
2654 +failed_read1:
2655 + return NULL;
2656 +}
2657 +
2658 +
2659 +static int get_dir_index_using_offset(struct super_block *s, long long
2660 + *next_block, unsigned int *next_offset,
2661 + long long index_start,
2662 + unsigned int index_offset, int i_count,
2663 + long long f_pos)
2664 +{
2665 + struct squashfs_sb_info *msblk = s->s_fs_info;
2666 + struct squashfs_super_block *sblk = &msblk->sblk;
2667 + int i, length = 0;
2668 + struct squashfs_dir_index_2 index;
2669 +
2670 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2671 + i_count, (unsigned int) f_pos);
2672 +
2673 + if (f_pos == 0)
2674 + goto finish;
2675 +
2676 + for (i = 0; i < i_count; i++) {
2677 + if (msblk->swap) {
2678 + struct squashfs_dir_index_2 sindex;
2679 + squashfs_get_cached_block(s, (char *) &sindex,
2680 + index_start, index_offset,
2681 + sizeof(sindex), &index_start,
2682 + &index_offset);
2683 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2684 + } else
2685 + squashfs_get_cached_block(s, (char *) &index,
2686 + index_start, index_offset,
2687 + sizeof(index), &index_start,
2688 + &index_offset);
2689 +
2690 + if (index.index > f_pos)
2691 + break;
2692 +
2693 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2694 + index.size + 1, &index_start,
2695 + &index_offset);
2696 +
2697 + length = index.index;
2698 + *next_block = index.start_block + sblk->directory_table_start;
2699 + }
2700 +
2701 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2702 +
2703 +finish:
2704 + return length;
2705 +}
2706 +
2707 +
2708 +static int get_dir_index_using_name(struct super_block *s, long long
2709 + *next_block, unsigned int *next_offset,
2710 + long long index_start,
2711 + unsigned int index_offset, int i_count,
2712 + const char *name, int size)
2713 +{
2714 + struct squashfs_sb_info *msblk = s->s_fs_info;
2715 + struct squashfs_super_block *sblk = &msblk->sblk;
2716 + int i, length = 0;
2717 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2718 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2719 + char str[SQUASHFS_NAME_LEN + 1];
2720 +
2721 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2722 +
2723 + strncpy(str, name, size);
2724 + str[size] = '\0';
2725 +
2726 + for (i = 0; i < i_count; i++) {
2727 + if (msblk->swap) {
2728 + struct squashfs_dir_index_2 sindex;
2729 + squashfs_get_cached_block(s, (char *) &sindex,
2730 + index_start, index_offset,
2731 + sizeof(sindex), &index_start,
2732 + &index_offset);
2733 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2734 + } else
2735 + squashfs_get_cached_block(s, (char *) index,
2736 + index_start, index_offset,
2737 + sizeof(struct squashfs_dir_index_2),
2738 + &index_start, &index_offset);
2739 +
2740 + squashfs_get_cached_block(s, index->name, index_start,
2741 + index_offset, index->size + 1,
2742 + &index_start, &index_offset);
2743 +
2744 + index->name[index->size + 1] = '\0';
2745 +
2746 + if (strcmp(index->name, str) > 0)
2747 + break;
2748 +
2749 + length = index->index;
2750 + *next_block = index->start_block + sblk->directory_table_start;
2751 + }
2752 +
2753 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2754 + return length;
2755 +}
2756 +
2757 +
2758 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2759 +{
2760 + struct inode *i = file->f_dentry->d_inode;
2761 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2762 + struct squashfs_super_block *sblk = &msblk->sblk;
2763 + long long next_block = SQUASHFS_I(i)->start_block +
2764 + sblk->directory_table_start;
2765 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2766 + dir_count;
2767 + struct squashfs_dir_header_2 dirh;
2768 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2769 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2770 +
2771 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2772 +
2773 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2774 + SQUASHFS_I(i)->u.s2.directory_index_start,
2775 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2776 + SQUASHFS_I(i)->u.s2.directory_index_count,
2777 + file->f_pos);
2778 +
2779 + while (length < i_size_read(i)) {
2780 + /* read directory header */
2781 + if (msblk->swap) {
2782 + struct squashfs_dir_header_2 sdirh;
2783 +
2784 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2785 + next_block, next_offset, sizeof(sdirh),
2786 + &next_block, &next_offset))
2787 + goto failed_read;
2788 +
2789 + length += sizeof(sdirh);
2790 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2791 + } else {
2792 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2793 + next_block, next_offset, sizeof(dirh),
2794 + &next_block, &next_offset))
2795 + goto failed_read;
2796 +
2797 + length += sizeof(dirh);
2798 + }
2799 +
2800 + dir_count = dirh.count + 1;
2801 + while (dir_count--) {
2802 + if (msblk->swap) {
2803 + struct squashfs_dir_entry_2 sdire;
2804 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2805 + &sdire, next_block, next_offset,
2806 + sizeof(sdire), &next_block,
2807 + &next_offset))
2808 + goto failed_read;
2809 +
2810 + length += sizeof(sdire);
2811 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2812 + } else {
2813 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2814 + dire, next_block, next_offset,
2815 + sizeof(*dire), &next_block,
2816 + &next_offset))
2817 + goto failed_read;
2818 +
2819 + length += sizeof(*dire);
2820 + }
2821 +
2822 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2823 + next_block, next_offset,
2824 + dire->size + 1, &next_block,
2825 + &next_offset))
2826 + goto failed_read;
2827 +
2828 + length += dire->size + 1;
2829 +
2830 + if (file->f_pos >= length)
2831 + continue;
2832 +
2833 + dire->name[dire->size + 1] = '\0';
2834 +
2835 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2836 + (unsigned int) dirent, dire->name,
2837 + dire->size + 1, (int) file->f_pos,
2838 + dirh.start_block, dire->offset,
2839 + squashfs_filetype_table[dire->type]);
2840 +
2841 + if (filldir(dirent, dire->name, dire->size + 1,
2842 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2843 + dirh.start_block, dire->offset),
2844 + squashfs_filetype_table[dire->type])
2845 + < 0) {
2846 + TRACE("Filldir returned less than 0\n");
2847 + goto finish;
2848 + }
2849 + file->f_pos = length;
2850 + dirs_read++;
2851 + }
2852 + }
2853 +
2854 +finish:
2855 + return dirs_read;
2856 +
2857 +failed_read:
2858 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2859 + next_offset);
2860 + return 0;
2861 +}
2862 +
2863 +
2864 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2865 + struct nameidata *nd)
2866 +{
2867 + const unsigned char *name = dentry->d_name.name;
2868 + int len = dentry->d_name.len;
2869 + struct inode *inode = NULL;
2870 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2871 + struct squashfs_super_block *sblk = &msblk->sblk;
2872 + long long next_block = SQUASHFS_I(i)->start_block +
2873 + sblk->directory_table_start;
2874 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2875 + dir_count;
2876 + struct squashfs_dir_header_2 dirh;
2877 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2878 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2879 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2880 +
2881 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2882 +
2883 + if (len > SQUASHFS_NAME_LEN)
2884 + goto exit_loop;
2885 +
2886 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2887 + SQUASHFS_I(i)->u.s2.directory_index_start,
2888 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2889 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2890 + len);
2891 +
2892 + while (length < i_size_read(i)) {
2893 + /* read directory header */
2894 + if (msblk->swap) {
2895 + struct squashfs_dir_header_2 sdirh;
2896 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2897 + next_block, next_offset, sizeof(sdirh),
2898 + &next_block, &next_offset))
2899 + goto failed_read;
2900 +
2901 + length += sizeof(sdirh);
2902 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2903 + } else {
2904 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2905 + next_block, next_offset, sizeof(dirh),
2906 + &next_block, &next_offset))
2907 + goto failed_read;
2908 +
2909 + length += sizeof(dirh);
2910 + }
2911 +
2912 + dir_count = dirh.count + 1;
2913 + while (dir_count--) {
2914 + if (msblk->swap) {
2915 + struct squashfs_dir_entry_2 sdire;
2916 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2917 + &sdire, next_block,next_offset,
2918 + sizeof(sdire), &next_block,
2919 + &next_offset))
2920 + goto failed_read;
2921 +
2922 + length += sizeof(sdire);
2923 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2924 + } else {
2925 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2926 + dire, next_block,next_offset,
2927 + sizeof(*dire), &next_block,
2928 + &next_offset))
2929 + goto failed_read;
2930 +
2931 + length += sizeof(*dire);
2932 + }
2933 +
2934 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2935 + next_block, next_offset, dire->size + 1,
2936 + &next_block, &next_offset))
2937 + goto failed_read;
2938 +
2939 + length += dire->size + 1;
2940 +
2941 + if (sorted && name[0] < dire->name[0])
2942 + goto exit_loop;
2943 +
2944 + if ((len == dire->size + 1) && !strncmp(name,
2945 + dire->name, len)) {
2946 + squashfs_inode_t ino =
2947 + SQUASHFS_MKINODE(dirh.start_block,
2948 + dire->offset);
2949 +
2950 + TRACE("calling squashfs_iget for directory "
2951 + "entry %s, inode %x:%x, %lld\n", name,
2952 + dirh.start_block, dire->offset, ino);
2953 +
2954 + inode = (msblk->iget)(i->i_sb, ino);
2955 +
2956 + goto exit_loop;
2957 + }
2958 + }
2959 + }
2960 +
2961 +exit_loop:
2962 + d_add(dentry, inode);
2963 + return ERR_PTR(0);
2964 +
2965 +failed_read:
2966 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2967 + next_offset);
2968 + goto exit_loop;
2969 +}
2970 +
2971 +
2972 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2973 +{
2974 + struct squashfs_super_block *sblk = &msblk->sblk;
2975 +
2976 + msblk->iget = squashfs_iget_2;
2977 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2978 +
2979 + sblk->bytes_used = sblk->bytes_used_2;
2980 + sblk->uid_start = sblk->uid_start_2;
2981 + sblk->guid_start = sblk->guid_start_2;
2982 + sblk->inode_table_start = sblk->inode_table_start_2;
2983 + sblk->directory_table_start = sblk->directory_table_start_2;
2984 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2985 +
2986 + return 1;
2987 +}
2988 diff -urN linux-2.6.21.1.old/fs/squashfs/squashfs.h linux-2.6.21.1.dev/fs/squashfs/squashfs.h
2989 --- linux-2.6.21.1.old/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
2990 +++ linux-2.6.21.1.dev/fs/squashfs/squashfs.h 2007-05-26 19:00:37.125351152 +0200
2991 @@ -0,0 +1,86 @@
2992 +/*
2993 + * Squashfs - a compressed read only filesystem for Linux
2994 + *
2995 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2996 + * Phillip Lougher <phillip@lougher.org.uk>
2997 + *
2998 + * This program is free software; you can redistribute it and/or
2999 + * modify it under the terms of the GNU General Public License
3000 + * as published by the Free Software Foundation; either version 2,
3001 + * or (at your option) any later version.
3002 + *
3003 + * This program is distributed in the hope that it will be useful,
3004 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3005 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3006 + * GNU General Public License for more details.
3007 + *
3008 + * You should have received a copy of the GNU General Public License
3009 + * along with this program; if not, write to the Free Software
3010 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3011 + *
3012 + * squashfs.h
3013 + */
3014 +
3015 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3016 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3017 +#endif
3018 +
3019 +#ifdef SQUASHFS_TRACE
3020 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3021 +#else
3022 +#define TRACE(s, args...) {}
3023 +#endif
3024 +
3025 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3026 +
3027 +#define SERROR(s, args...) do { \
3028 + if (!silent) \
3029 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3030 + } while(0)
3031 +
3032 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3033 +
3034 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3035 +{
3036 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3037 +}
3038 +
3039 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3040 +#define SQSH_EXTERN
3041 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3042 + long long index, unsigned int length,
3043 + long long *next_index);
3044 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3045 + long long block, unsigned int offset,
3046 + int length, long long *next_block,
3047 + unsigned int *next_offset);
3048 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3049 + squashfs_fragment_cache *fragment);
3050 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3051 + *s, long long start_block,
3052 + int length);
3053 +extern struct address_space_operations squashfs_symlink_aops;
3054 +extern struct address_space_operations squashfs_aops;
3055 +extern struct address_space_operations squashfs_aops_4K;
3056 +extern struct inode_operations squashfs_dir_inode_ops;
3057 +#else
3058 +#define SQSH_EXTERN static
3059 +#endif
3060 +
3061 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3062 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3063 +#else
3064 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3065 +{
3066 + return 0;
3067 +}
3068 +#endif
3069 +
3070 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3071 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3072 +#else
3073 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3074 +{
3075 + return 0;
3076 +}
3077 +#endif
3078 diff -urN linux-2.6.21.1.old/include/linux/squashfs_fs.h linux-2.6.21.1.dev/include/linux/squashfs_fs.h
3079 --- linux-2.6.21.1.old/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3080 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs.h 2007-05-26 19:00:37.143348416 +0200
3081 @@ -0,0 +1,911 @@
3082 +#ifndef SQUASHFS_FS
3083 +#define SQUASHFS_FS
3084 +
3085 +/*
3086 + * Squashfs
3087 + *
3088 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3089 + * Phillip Lougher <phillip@lougher.org.uk>
3090 + *
3091 + * This program is free software; you can redistribute it and/or
3092 + * modify it under the terms of the GNU General Public License
3093 + * as published by the Free Software Foundation; either version 2,
3094 + * or (at your option) any later version.
3095 + *
3096 + * This program is distributed in the hope that it will be useful,
3097 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3099 + * GNU General Public License for more details.
3100 + *
3101 + * You should have received a copy of the GNU General Public License
3102 + * along with this program; if not, write to the Free Software
3103 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3104 + *
3105 + * squashfs_fs.h
3106 + */
3107 +
3108 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3109 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3110 +#endif
3111 +
3112 +#ifdef CONFIG_SQUASHFS_VMALLOC
3113 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3114 +#define SQUASHFS_FREE(a) vfree(a)
3115 +#else
3116 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3117 +#define SQUASHFS_FREE(a) kfree(a)
3118 +#endif
3119 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3120 +#define SQUASHFS_MAJOR 3
3121 +#define SQUASHFS_MINOR 0
3122 +#define SQUASHFS_MAGIC 0x73717368
3123 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3124 +#define SQUASHFS_START 0
3125 +
3126 +/* size of metadata (inode and directory) blocks */
3127 +#define SQUASHFS_METADATA_SIZE 8192
3128 +#define SQUASHFS_METADATA_LOG 13
3129 +
3130 +/* default size of data blocks */
3131 +#define SQUASHFS_FILE_SIZE 65536
3132 +#define SQUASHFS_FILE_LOG 16
3133 +
3134 +#define SQUASHFS_FILE_MAX_SIZE 65536
3135 +
3136 +/* Max number of uids and gids */
3137 +#define SQUASHFS_UIDS 256
3138 +#define SQUASHFS_GUIDS 255
3139 +
3140 +/* Max length of filename (not 255) */
3141 +#define SQUASHFS_NAME_LEN 256
3142 +
3143 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3144 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3145 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3146 +#define SQUASHFS_USED_BLK ((long long) -2)
3147 +
3148 +/* Filesystem flags */
3149 +#define SQUASHFS_NOI 0
3150 +#define SQUASHFS_NOD 1
3151 +#define SQUASHFS_CHECK 2
3152 +#define SQUASHFS_NOF 3
3153 +#define SQUASHFS_NO_FRAG 4
3154 +#define SQUASHFS_ALWAYS_FRAG 5
3155 +#define SQUASHFS_DUPLICATE 6
3156 +
3157 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3158 +
3159 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3160 + SQUASHFS_NOI)
3161 +
3162 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3163 + SQUASHFS_NOD)
3164 +
3165 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3166 + SQUASHFS_NOF)
3167 +
3168 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3169 + SQUASHFS_NO_FRAG)
3170 +
3171 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3172 + SQUASHFS_ALWAYS_FRAG)
3173 +
3174 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3175 + SQUASHFS_DUPLICATE)
3176 +
3177 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3178 + SQUASHFS_CHECK)
3179 +
3180 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3181 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3182 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3183 + (duplicate_checking << 6))
3184 +
3185 +/* Max number of types and file types */
3186 +#define SQUASHFS_DIR_TYPE 1
3187 +#define SQUASHFS_FILE_TYPE 2
3188 +#define SQUASHFS_SYMLINK_TYPE 3
3189 +#define SQUASHFS_BLKDEV_TYPE 4
3190 +#define SQUASHFS_CHRDEV_TYPE 5
3191 +#define SQUASHFS_FIFO_TYPE 6
3192 +#define SQUASHFS_SOCKET_TYPE 7
3193 +#define SQUASHFS_LDIR_TYPE 8
3194 +#define SQUASHFS_LREG_TYPE 9
3195 +
3196 +/* 1.0 filesystem type definitions */
3197 +#define SQUASHFS_TYPES 5
3198 +#define SQUASHFS_IPC_TYPE 0
3199 +
3200 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3201 + * uncompressed */
3202 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3203 +
3204 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3205 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3206 +
3207 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3208 +
3209 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3210 +
3211 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3212 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3213 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3214 +
3215 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3216 +
3217 +/*
3218 + * Inode number ops. Inodes consist of a compressed block number, and an
3219 + * uncompressed offset within that block
3220 + */
3221 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3222 +
3223 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3224 +
3225 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3226 + << 16) + (B)))
3227 +
3228 +/* Compute 32 bit VFS inode number from squashfs inode number */
3229 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3230 + ((b) >> 2) + 1))
3231 +/* XXX */
3232 +
3233 +/* Translate between VFS mode and squashfs mode */
3234 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3235 +
3236 +/* fragment and fragment table defines */
3237 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3238 +
3239 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3240 + SQUASHFS_METADATA_SIZE)
3241 +
3242 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3243 + SQUASHFS_METADATA_SIZE)
3244 +
3245 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3246 + SQUASHFS_METADATA_SIZE - 1) / \
3247 + SQUASHFS_METADATA_SIZE)
3248 +
3249 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3250 + sizeof(long long))
3251 +
3252 +/* cached data constants for filesystem */
3253 +#define SQUASHFS_CACHED_BLKS 8
3254 +
3255 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3256 +
3257 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3258 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3259 +
3260 +#define SQUASHFS_MARKER_BYTE 0xff
3261 +
3262 +/* meta index cache */
3263 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3264 +#define SQUASHFS_META_ENTRIES 31
3265 +#define SQUASHFS_META_NUMBER 8
3266 +#define SQUASHFS_SLOTS 4
3267 +
3268 +struct meta_entry {
3269 + long long data_block;
3270 + unsigned int index_block;
3271 + unsigned short offset;
3272 + unsigned short pad;
3273 +};
3274 +
3275 +struct meta_index {
3276 + unsigned int inode_number;
3277 + unsigned int offset;
3278 + unsigned short entries;
3279 + unsigned short skip;
3280 + unsigned short locked;
3281 + unsigned short pad;
3282 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3283 +};
3284 +
3285 +
3286 +/*
3287 + * definitions for structures on disk
3288 + */
3289 +
3290 +typedef long long squashfs_block_t;
3291 +typedef long long squashfs_inode_t;
3292 +
3293 +struct squashfs_super_block {
3294 + unsigned int s_magic;
3295 + unsigned int inodes;
3296 + unsigned int bytes_used_2;
3297 + unsigned int uid_start_2;
3298 + unsigned int guid_start_2;
3299 + unsigned int inode_table_start_2;
3300 + unsigned int directory_table_start_2;
3301 + unsigned int s_major:16;
3302 + unsigned int s_minor:16;
3303 + unsigned int block_size_1:16;
3304 + unsigned int block_log:16;
3305 + unsigned int flags:8;
3306 + unsigned int no_uids:8;
3307 + unsigned int no_guids:8;
3308 + unsigned int mkfs_time /* time of filesystem creation */;
3309 + squashfs_inode_t root_inode;
3310 + unsigned int block_size;
3311 + unsigned int fragments;
3312 + unsigned int fragment_table_start_2;
3313 + long long bytes_used;
3314 + long long uid_start;
3315 + long long guid_start;
3316 + long long inode_table_start;
3317 + long long directory_table_start;
3318 + long long fragment_table_start;
3319 + long long unused;
3320 +} __attribute__ ((packed));
3321 +
3322 +struct squashfs_dir_index {
3323 + unsigned int index;
3324 + unsigned int start_block;
3325 + unsigned char size;
3326 + unsigned char name[0];
3327 +} __attribute__ ((packed));
3328 +
3329 +#define SQUASHFS_BASE_INODE_HEADER \
3330 + unsigned int inode_type:4; \
3331 + unsigned int mode:12; \
3332 + unsigned int uid:8; \
3333 + unsigned int guid:8; \
3334 + unsigned int mtime; \
3335 + unsigned int inode_number;
3336 +
3337 +struct squashfs_base_inode_header {
3338 + SQUASHFS_BASE_INODE_HEADER;
3339 +} __attribute__ ((packed));
3340 +
3341 +struct squashfs_ipc_inode_header {
3342 + SQUASHFS_BASE_INODE_HEADER;
3343 + unsigned int nlink;
3344 +} __attribute__ ((packed));
3345 +
3346 +struct squashfs_dev_inode_header {
3347 + SQUASHFS_BASE_INODE_HEADER;
3348 + unsigned int nlink;
3349 + unsigned short rdev;
3350 +} __attribute__ ((packed));
3351 +
3352 +struct squashfs_symlink_inode_header {
3353 + SQUASHFS_BASE_INODE_HEADER;
3354 + unsigned int nlink;
3355 + unsigned short symlink_size;
3356 + char symlink[0];
3357 +} __attribute__ ((packed));
3358 +
3359 +struct squashfs_reg_inode_header {
3360 + SQUASHFS_BASE_INODE_HEADER;
3361 + squashfs_block_t start_block;
3362 + unsigned int fragment;
3363 + unsigned int offset;
3364 + unsigned int file_size;
3365 + unsigned short block_list[0];
3366 +} __attribute__ ((packed));
3367 +
3368 +struct squashfs_lreg_inode_header {
3369 + SQUASHFS_BASE_INODE_HEADER;
3370 + unsigned int nlink;
3371 + squashfs_block_t start_block;
3372 + unsigned int fragment;
3373 + unsigned int offset;
3374 + long long file_size;
3375 + unsigned short block_list[0];
3376 +} __attribute__ ((packed));
3377 +
3378 +struct squashfs_dir_inode_header {
3379 + SQUASHFS_BASE_INODE_HEADER;
3380 + unsigned int nlink;
3381 + unsigned int file_size:19;
3382 + unsigned int offset:13;
3383 + unsigned int start_block;
3384 + unsigned int parent_inode;
3385 +} __attribute__ ((packed));
3386 +
3387 +struct squashfs_ldir_inode_header {
3388 + SQUASHFS_BASE_INODE_HEADER;
3389 + unsigned int nlink;
3390 + unsigned int file_size:27;
3391 + unsigned int offset:13;
3392 + unsigned int start_block;
3393 + unsigned int i_count:16;
3394 + unsigned int parent_inode;
3395 + struct squashfs_dir_index index[0];
3396 +} __attribute__ ((packed));
3397 +
3398 +union squashfs_inode_header {
3399 + struct squashfs_base_inode_header base;
3400 + struct squashfs_dev_inode_header dev;
3401 + struct squashfs_symlink_inode_header symlink;
3402 + struct squashfs_reg_inode_header reg;
3403 + struct squashfs_lreg_inode_header lreg;
3404 + struct squashfs_dir_inode_header dir;
3405 + struct squashfs_ldir_inode_header ldir;
3406 + struct squashfs_ipc_inode_header ipc;
3407 +};
3408 +
3409 +struct squashfs_dir_entry {
3410 + unsigned int offset:13;
3411 + unsigned int type:3;
3412 + unsigned int size:8;
3413 + int inode_number:16;
3414 + char name[0];
3415 +} __attribute__ ((packed));
3416 +
3417 +struct squashfs_dir_header {
3418 + unsigned int count:8;
3419 + unsigned int start_block;
3420 + unsigned int inode_number;
3421 +} __attribute__ ((packed));
3422 +
3423 +struct squashfs_fragment_entry {
3424 + long long start_block;
3425 + unsigned int size;
3426 + unsigned int unused;
3427 +} __attribute__ ((packed));
3428 +
3429 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3430 +extern int squashfs_uncompress_init(void);
3431 +extern int squashfs_uncompress_exit(void);
3432 +
3433 +/*
3434 + * macros to convert each packed bitfield structure from little endian to big
3435 + * endian and vice versa. These are needed when creating or using a filesystem
3436 + * on a machine with different byte ordering to the target architecture.
3437 + *
3438 + */
3439 +
3440 +#define SQUASHFS_SWAP_START \
3441 + int bits;\
3442 + int b_pos;\
3443 + unsigned long long val;\
3444 + unsigned char *s;\
3445 + unsigned char *d;
3446 +
3447 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3448 + SQUASHFS_SWAP_START\
3449 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3450 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3451 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3452 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3453 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3454 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3455 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3456 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3457 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3458 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3459 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3460 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3461 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3462 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3463 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3464 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3465 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3466 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3467 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3468 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3469 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3470 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3471 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3472 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3473 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3474 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3475 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3476 +}
3477 +
3478 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3479 + SQUASHFS_MEMSET(s, d, n);\
3480 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3481 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3482 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3483 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3484 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3485 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3486 +
3487 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3488 + SQUASHFS_SWAP_START\
3489 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3490 +}
3491 +
3492 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3493 + SQUASHFS_SWAP_START\
3494 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3495 + sizeof(struct squashfs_ipc_inode_header))\
3496 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3497 +}
3498 +
3499 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3500 + SQUASHFS_SWAP_START\
3501 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3502 + sizeof(struct squashfs_dev_inode_header)); \
3503 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3504 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3505 +}
3506 +
3507 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3508 + SQUASHFS_SWAP_START\
3509 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3510 + sizeof(struct squashfs_symlink_inode_header));\
3511 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3512 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3513 +}
3514 +
3515 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3516 + SQUASHFS_SWAP_START\
3517 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3518 + sizeof(struct squashfs_reg_inode_header));\
3519 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3520 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3521 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3522 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3523 +}
3524 +
3525 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3526 + SQUASHFS_SWAP_START\
3527 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3528 + sizeof(struct squashfs_lreg_inode_header));\
3529 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3530 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3531 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3532 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3533 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3534 +}
3535 +
3536 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3537 + SQUASHFS_SWAP_START\
3538 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3539 + sizeof(struct squashfs_dir_inode_header));\
3540 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3541 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3542 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3543 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3544 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3545 +}
3546 +
3547 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3548 + SQUASHFS_SWAP_START\
3549 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 + sizeof(struct squashfs_ldir_inode_header));\
3551 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3553 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3554 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3555 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3556 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3557 +}
3558 +
3559 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3560 + SQUASHFS_SWAP_START\
3561 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3562 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3563 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3564 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3565 +}
3566 +
3567 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3568 + SQUASHFS_SWAP_START\
3569 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3570 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3571 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3572 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3573 +}
3574 +
3575 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3576 + SQUASHFS_SWAP_START\
3577 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3578 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3579 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3580 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3581 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3582 +}
3583 +
3584 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3585 + SQUASHFS_SWAP_START\
3586 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3587 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3588 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3589 +}
3590 +
3591 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3592 + int entry;\
3593 + int bit_position;\
3594 + SQUASHFS_SWAP_START\
3595 + SQUASHFS_MEMSET(s, d, n * 2);\
3596 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3597 + 16)\
3598 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3599 +}
3600 +
3601 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3602 + int entry;\
3603 + int bit_position;\
3604 + SQUASHFS_SWAP_START\
3605 + SQUASHFS_MEMSET(s, d, n * 4);\
3606 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3607 + 32)\
3608 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3609 +}
3610 +
3611 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3612 + int entry;\
3613 + int bit_position;\
3614 + SQUASHFS_SWAP_START\
3615 + SQUASHFS_MEMSET(s, d, n * 8);\
3616 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3617 + 64)\
3618 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3619 +}
3620 +
3621 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3622 + int entry;\
3623 + int bit_position;\
3624 + SQUASHFS_SWAP_START\
3625 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3626 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3627 + bits)\
3628 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3629 +}
3630 +
3631 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3632 +
3633 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3634 +
3635 +struct squashfs_base_inode_header_1 {
3636 + unsigned int inode_type:4;
3637 + unsigned int mode:12; /* protection */
3638 + unsigned int uid:4; /* index into uid table */
3639 + unsigned int guid:4; /* index into guid table */
3640 +} __attribute__ ((packed));
3641 +
3642 +struct squashfs_ipc_inode_header_1 {
3643 + unsigned int inode_type:4;
3644 + unsigned int mode:12; /* protection */
3645 + unsigned int uid:4; /* index into uid table */
3646 + unsigned int guid:4; /* index into guid table */
3647 + unsigned int type:4;
3648 + unsigned int offset:4;
3649 +} __attribute__ ((packed));
3650 +
3651 +struct squashfs_dev_inode_header_1 {
3652 + unsigned int inode_type:4;
3653 + unsigned int mode:12; /* protection */
3654 + unsigned int uid:4; /* index into uid table */
3655 + unsigned int guid:4; /* index into guid table */
3656 + unsigned short rdev;
3657 +} __attribute__ ((packed));
3658 +
3659 +struct squashfs_symlink_inode_header_1 {
3660 + unsigned int inode_type:4;
3661 + unsigned int mode:12; /* protection */
3662 + unsigned int uid:4; /* index into uid table */
3663 + unsigned int guid:4; /* index into guid table */
3664 + unsigned short symlink_size;
3665 + char symlink[0];
3666 +} __attribute__ ((packed));
3667 +
3668 +struct squashfs_reg_inode_header_1 {
3669 + unsigned int inode_type:4;
3670 + unsigned int mode:12; /* protection */
3671 + unsigned int uid:4; /* index into uid table */
3672 + unsigned int guid:4; /* index into guid table */
3673 + unsigned int mtime;
3674 + unsigned int start_block;
3675 + unsigned int file_size:32;
3676 + unsigned short block_list[0];
3677 +} __attribute__ ((packed));
3678 +
3679 +struct squashfs_dir_inode_header_1 {
3680 + unsigned int inode_type:4;
3681 + unsigned int mode:12; /* protection */
3682 + unsigned int uid:4; /* index into uid table */
3683 + unsigned int guid:4; /* index into guid table */
3684 + unsigned int file_size:19;
3685 + unsigned int offset:13;
3686 + unsigned int mtime;
3687 + unsigned int start_block:24;
3688 +} __attribute__ ((packed));
3689 +
3690 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3691 + SQUASHFS_MEMSET(s, d, n);\
3692 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3693 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3694 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3695 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3696 +
3697 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3698 + SQUASHFS_SWAP_START\
3699 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3700 +}
3701 +
3702 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3703 + SQUASHFS_SWAP_START\
3704 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3705 + sizeof(struct squashfs_ipc_inode_header_1));\
3706 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3707 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3708 +}
3709 +
3710 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3711 + SQUASHFS_SWAP_START\
3712 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3713 + sizeof(struct squashfs_dev_inode_header_1));\
3714 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3715 +}
3716 +
3717 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3718 + SQUASHFS_SWAP_START\
3719 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3720 + sizeof(struct squashfs_symlink_inode_header_1));\
3721 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3722 +}
3723 +
3724 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3725 + SQUASHFS_SWAP_START\
3726 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3727 + sizeof(struct squashfs_reg_inode_header_1));\
3728 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3729 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3730 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3731 +}
3732 +
3733 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3734 + SQUASHFS_SWAP_START\
3735 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3736 + sizeof(struct squashfs_dir_inode_header_1));\
3737 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3738 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3739 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3740 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3741 +}
3742 +
3743 +#endif
3744 +
3745 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3746 +
3747 +struct squashfs_dir_index_2 {
3748 + unsigned int index:27;
3749 + unsigned int start_block:29;
3750 + unsigned char size;
3751 + unsigned char name[0];
3752 +} __attribute__ ((packed));
3753 +
3754 +struct squashfs_base_inode_header_2 {
3755 + unsigned int inode_type:4;
3756 + unsigned int mode:12; /* protection */
3757 + unsigned int uid:8; /* index into uid table */
3758 + unsigned int guid:8; /* index into guid table */
3759 +} __attribute__ ((packed));
3760 +
3761 +struct squashfs_ipc_inode_header_2 {
3762 + unsigned int inode_type:4;
3763 + unsigned int mode:12; /* protection */
3764 + unsigned int uid:8; /* index into uid table */
3765 + unsigned int guid:8; /* index into guid table */
3766 +} __attribute__ ((packed));
3767 +
3768 +struct squashfs_dev_inode_header_2 {
3769 + unsigned int inode_type:4;
3770 + unsigned int mode:12; /* protection */
3771 + unsigned int uid:8; /* index into uid table */
3772 + unsigned int guid:8; /* index into guid table */
3773 + unsigned short rdev;
3774 +} __attribute__ ((packed));
3775 +
3776 +struct squashfs_symlink_inode_header_2 {
3777 + unsigned int inode_type:4;
3778 + unsigned int mode:12; /* protection */
3779 + unsigned int uid:8; /* index into uid table */
3780 + unsigned int guid:8; /* index into guid table */
3781 + unsigned short symlink_size;
3782 + char symlink[0];
3783 +} __attribute__ ((packed));
3784 +
3785 +struct squashfs_reg_inode_header_2 {
3786 + unsigned int inode_type:4;
3787 + unsigned int mode:12; /* protection */
3788 + unsigned int uid:8; /* index into uid table */
3789 + unsigned int guid:8; /* index into guid table */
3790 + unsigned int mtime;
3791 + unsigned int start_block;
3792 + unsigned int fragment;
3793 + unsigned int offset;
3794 + unsigned int file_size:32;
3795 + unsigned short block_list[0];
3796 +} __attribute__ ((packed));
3797 +
3798 +struct squashfs_dir_inode_header_2 {
3799 + unsigned int inode_type:4;
3800 + unsigned int mode:12; /* protection */
3801 + unsigned int uid:8; /* index into uid table */
3802 + unsigned int guid:8; /* index into guid table */
3803 + unsigned int file_size:19;
3804 + unsigned int offset:13;
3805 + unsigned int mtime;
3806 + unsigned int start_block:24;
3807 +} __attribute__ ((packed));
3808 +
3809 +struct squashfs_ldir_inode_header_2 {
3810 + unsigned int inode_type:4;
3811 + unsigned int mode:12; /* protection */
3812 + unsigned int uid:8; /* index into uid table */
3813 + unsigned int guid:8; /* index into guid table */
3814 + unsigned int file_size:27;
3815 + unsigned int offset:13;
3816 + unsigned int mtime;
3817 + unsigned int start_block:24;
3818 + unsigned int i_count:16;
3819 + struct squashfs_dir_index_2 index[0];
3820 +} __attribute__ ((packed));
3821 +
3822 +union squashfs_inode_header_2 {
3823 + struct squashfs_base_inode_header_2 base;
3824 + struct squashfs_dev_inode_header_2 dev;
3825 + struct squashfs_symlink_inode_header_2 symlink;
3826 + struct squashfs_reg_inode_header_2 reg;
3827 + struct squashfs_dir_inode_header_2 dir;
3828 + struct squashfs_ldir_inode_header_2 ldir;
3829 + struct squashfs_ipc_inode_header_2 ipc;
3830 +};
3831 +
3832 +struct squashfs_dir_header_2 {
3833 + unsigned int count:8;
3834 + unsigned int start_block:24;
3835 +} __attribute__ ((packed));
3836 +
3837 +struct squashfs_dir_entry_2 {
3838 + unsigned int offset:13;
3839 + unsigned int type:3;
3840 + unsigned int size:8;
3841 + char name[0];
3842 +} __attribute__ ((packed));
3843 +
3844 +struct squashfs_fragment_entry_2 {
3845 + unsigned int start_block;
3846 + unsigned int size;
3847 +} __attribute__ ((packed));
3848 +
3849 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3850 + SQUASHFS_MEMSET(s, d, n);\
3851 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3852 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3853 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3854 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3855 +
3856 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3857 + SQUASHFS_SWAP_START\
3858 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3859 +}
3860 +
3861 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3862 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3863 +
3864 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3865 + SQUASHFS_SWAP_START\
3866 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3867 + sizeof(struct squashfs_dev_inode_header_2)); \
3868 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3869 +}
3870 +
3871 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3872 + SQUASHFS_SWAP_START\
3873 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3874 + sizeof(struct squashfs_symlink_inode_header_2));\
3875 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3876 +}
3877 +
3878 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3879 + SQUASHFS_SWAP_START\
3880 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3881 + sizeof(struct squashfs_reg_inode_header_2));\
3882 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3883 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3884 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3885 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3886 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3887 +}
3888 +
3889 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3890 + SQUASHFS_SWAP_START\
3891 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3892 + sizeof(struct squashfs_dir_inode_header_2));\
3893 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3894 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3895 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3896 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3897 +}
3898 +
3899 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3900 + SQUASHFS_SWAP_START\
3901 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3902 + sizeof(struct squashfs_ldir_inode_header_2));\
3903 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3904 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3905 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3906 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3907 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3908 +}
3909 +
3910 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3911 + SQUASHFS_SWAP_START\
3912 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3913 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3914 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3915 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3916 +}
3917 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3918 + SQUASHFS_SWAP_START\
3919 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3920 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3921 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3922 +}
3923 +
3924 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3925 + SQUASHFS_SWAP_START\
3926 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3927 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3928 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3929 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3930 +}
3931 +
3932 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3933 + SQUASHFS_SWAP_START\
3934 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3935 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3936 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3937 +}
3938 +
3939 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3940 +
3941 +/* fragment and fragment table defines */
3942 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3943 +
3944 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3945 + SQUASHFS_METADATA_SIZE)
3946 +
3947 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3948 + SQUASHFS_METADATA_SIZE)
3949 +
3950 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3951 + SQUASHFS_METADATA_SIZE - 1) / \
3952 + SQUASHFS_METADATA_SIZE)
3953 +
3954 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3955 + sizeof(int))
3956 +
3957 +#endif
3958 +
3959 +#ifdef __KERNEL__
3960 +
3961 +/*
3962 + * macros used to swap each structure entry, taking into account
3963 + * bitfields and different bitfield placing conventions on differing
3964 + * architectures
3965 + */
3966 +
3967 +#include <asm/byteorder.h>
3968 +
3969 +#ifdef __BIG_ENDIAN
3970 + /* convert from little endian to big endian */
3971 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3972 + tbits, b_pos)
3973 +#else
3974 + /* convert from big endian to little endian */
3975 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3976 + tbits, 64 - tbits - b_pos)
3977 +#endif
3978 +
3979 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3980 + b_pos = pos % 8;\
3981 + val = 0;\
3982 + s = (unsigned char *)p + (pos / 8);\
3983 + d = ((unsigned char *) &val) + 7;\
3984 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3985 + *d-- = *s++;\
3986 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3987 +}
3988 +
3989 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3990 +
3991 +#endif
3992 +#endif
3993 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
3994 --- linux-2.6.21.1.old/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
3995 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs_i.h 2007-05-26 19:00:37.143348416 +0200
3996 @@ -0,0 +1,45 @@
3997 +#ifndef SQUASHFS_FS_I
3998 +#define SQUASHFS_FS_I
3999 +/*
4000 + * Squashfs
4001 + *
4002 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4003 + * Phillip Lougher <phillip@lougher.org.uk>
4004 + *
4005 + * This program is free software; you can redistribute it and/or
4006 + * modify it under the terms of the GNU General Public License
4007 + * as published by the Free Software Foundation; either version 2,
4008 + * or (at your option) any later version.
4009 + *
4010 + * This program is distributed in the hope that it will be useful,
4011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4013 + * GNU General Public License for more details.
4014 + *
4015 + * You should have received a copy of the GNU General Public License
4016 + * along with this program; if not, write to the Free Software
4017 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4018 + *
4019 + * squashfs_fs_i.h
4020 + */
4021 +
4022 +struct squashfs_inode_info {
4023 + long long start_block;
4024 + unsigned int offset;
4025 + union {
4026 + struct {
4027 + long long fragment_start_block;
4028 + unsigned int fragment_size;
4029 + unsigned int fragment_offset;
4030 + long long block_list_start;
4031 + } s1;
4032 + struct {
4033 + long long directory_index_start;
4034 + unsigned int directory_index_offset;
4035 + unsigned int directory_index_count;
4036 + unsigned int parent_inode;
4037 + } s2;
4038 + } u;
4039 + struct inode vfs_inode;
4040 +};
4041 +#endif
4042 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
4043 --- linux-2.6.21.1.old/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4044 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs_sb.h 2007-05-26 19:00:37.144348264 +0200
4045 @@ -0,0 +1,74 @@
4046 +#ifndef SQUASHFS_FS_SB
4047 +#define SQUASHFS_FS_SB
4048 +/*
4049 + * Squashfs
4050 + *
4051 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4052 + * Phillip Lougher <phillip@lougher.org.uk>
4053 + *
4054 + * This program is free software; you can redistribute it and/or
4055 + * modify it under the terms of the GNU General Public License
4056 + * as published by the Free Software Foundation; either version 2,
4057 + * or (at your option) any later version.
4058 + *
4059 + * This program is distributed in the hope that it will be useful,
4060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4062 + * GNU General Public License for more details.
4063 + *
4064 + * You should have received a copy of the GNU General Public License
4065 + * along with this program; if not, write to the Free Software
4066 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4067 + *
4068 + * squashfs_fs_sb.h
4069 + */
4070 +
4071 +#include <linux/squashfs_fs.h>
4072 +
4073 +struct squashfs_cache {
4074 + long long block;
4075 + int length;
4076 + long long next_index;
4077 + char *data;
4078 +};
4079 +
4080 +struct squashfs_fragment_cache {
4081 + long long block;
4082 + int length;
4083 + unsigned int locked;
4084 + char *data;
4085 +};
4086 +
4087 +struct squashfs_sb_info {
4088 + struct squashfs_super_block sblk;
4089 + int devblksize;
4090 + int devblksize_log2;
4091 + int swap;
4092 + struct squashfs_cache *block_cache;
4093 + struct squashfs_fragment_cache *fragment;
4094 + int next_cache;
4095 + int next_fragment;
4096 + int next_meta_index;
4097 + unsigned int *uid;
4098 + unsigned int *guid;
4099 + long long *fragment_index;
4100 + unsigned int *fragment_index_2;
4101 + unsigned int read_size;
4102 + char *read_data;
4103 + char *read_page;
4104 + struct semaphore read_data_mutex;
4105 + struct semaphore read_page_mutex;
4106 + struct semaphore block_cache_mutex;
4107 + struct semaphore fragment_mutex;
4108 + struct semaphore meta_index_mutex;
4109 + wait_queue_head_t waitq;
4110 + wait_queue_head_t fragment_wait_queue;
4111 + struct meta_index *meta_index;
4112 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4113 + inode);
4114 + long long (*read_blocklist)(struct inode *inode, int \
4115 + index, int readahead_blks, char *block_list, \
4116 + unsigned short **block_p, unsigned int *bsize);
4117 + int (*read_fragment_index_table)(struct super_block *s);
4118 +};
4119 +#endif
4120 diff -urN linux-2.6.21.1.old/init/do_mounts_rd.c linux-2.6.21.1.dev/init/do_mounts_rd.c
4121 --- linux-2.6.21.1.old/init/do_mounts_rd.c 2007-04-27 23:49:26.000000000 +0200
4122 +++ linux-2.6.21.1.dev/init/do_mounts_rd.c 2007-05-26 19:00:37.144348264 +0200
4123 @@ -5,6 +5,7 @@
4124 #include <linux/ext2_fs.h>
4125 #include <linux/romfs_fs.h>
4126 #include <linux/cramfs_fs.h>
4127 +#include <linux/squashfs_fs.h>
4128 #include <linux/initrd.h>
4129 #include <linux/string.h>
4130
4131 @@ -39,6 +40,7 @@
4132 * numbers could not be found.
4133 *
4134 * We currently check for the following magic numbers:
4135 + * squashfs
4136 * minix
4137 * ext2
4138 * romfs
4139 @@ -53,6 +55,7 @@
4140 struct ext2_super_block *ext2sb;
4141 struct romfs_super_block *romfsb;
4142 struct cramfs_super *cramfsb;
4143 + struct squashfs_super_block *squashfsb;
4144 int nblocks = -1;
4145 unsigned char *buf;
4146
4147 @@ -64,6 +67,7 @@
4148 ext2sb = (struct ext2_super_block *) buf;
4149 romfsb = (struct romfs_super_block *) buf;
4150 cramfsb = (struct cramfs_super *) buf;
4151 + squashfsb = (struct squashfs_super_block *) buf;
4152 memset(buf, 0xe5, size);
4153
4154 /*
4155 @@ -101,6 +105,15 @@
4156 goto done;
4157 }
4158
4159 + /* squashfs is at block zero too */
4160 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4161 + printk(KERN_NOTICE
4162 + "RAMDISK: squashfs filesystem found at block %d\n",
4163 + start_block);
4164 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4165 + goto done;
4166 + }
4167 +
4168 /*
4169 * Read block 1 to test for minix and ext2 superblock
4170 */
This page took 0.223322 seconds and 5 git commands to generate.