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