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