/[linux-patches]/genpatches-2.6/tags/2.6.28-1/4300_squashfs-3.4.patch
Gentoo

Contents of /genpatches-2.6/tags/2.6.28-1/4300_squashfs-3.4.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20