/[linux-patches]/genpatches-2.6/trunk/2.6.18/4300_squashfs-3.1.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.18/4300_squashfs-3.1.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20