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