/[linux-patches]/genpatches-2.6/trunk/2.6.22-pre/4300_squashfs-3.2.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.22-pre/4300_squashfs-3.2.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20