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