/[linux-patches]/genpatches-2.6/tags/2.6.20-9/4300_squashfs-3.2.patch
Gentoo

Contents of /genpatches-2.6/tags/2.6.20-9/4300_squashfs-3.2.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20