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