/[linux-patches]/genpatches-2.6/trunk/2.6.16-pre/4705_squashfs-2.2.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.16-pre/4705_squashfs-2.2.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 278 - (show annotations) (download)
Sun Jan 22 14:13:45 2006 UTC (12 years, 6 months ago) by phreak
File size: 87842 byte(s)
Rediffing 4705_squashfs-2.2.patch
1 Index: linux-git/fs/Kconfig
2 ===================================================================
3 --- linux-git.orig/fs/Kconfig
4 +++ linux-git/fs/Kconfig
5 @@ -1195,6 +1195,69 @@ config CRAMFS
6
7 If unsure, say N.
8
9 +config SQUASHFS
10 + tristate "SquashFS 2.0 - Squashed file system support"
11 + select ZLIB_INFLATE
12 + help
13 + Saying Y here includes support for SquashFs 2.0 (Compressed Read-Only File
14 + System). Squashfs is a highly compressed read-only filesystem for Linux.
15 + It uses zlib compression to compress both files, inodes and directories.
16 + Inodes in the system are very small and all blocks are packed to minimise
17 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
18 +
19 + Squashfs is intended for general read-only filesystem use, for archival
20 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
21 + systems where low overhead is needed. Further information and filesystem tools
22 + are available from http://squashfs.sourceforge.net.
23 +
24 + If you want to compile this as a module ( = code which can be
25 + inserted in and removed from the running kernel whenever you want),
26 + say M here and read <file:Documentation/modules.txt>. The module
27 + will be called squashfs. Note that the root file system (the one
28 + containing the directory /) cannot be compiled as a module.
29 +
30 + If unsure, say N.
31 +
32 +config SQUASHFS_EMBEDDED
33 +
34 + bool "Additional options for memory-constrained systems"
35 + depends on SQUASHFS
36 + default n
37 + help
38 + Saying Y here allows you to specify cache sizes and how Squashfs
39 + allocates memory. This is only intended for memory constrained
40 + systems.
41 +
42 + If unsure, say N.
43 +
44 +config SQUASHFS_FRAGMENT_CACHE_SIZE
45 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
46 + depends on SQUASHFS
47 + default "3"
48 + help
49 + By default SquashFS caches the last 3 fragments read from
50 + the filesystem. Increasing this amount may mean SquashFS
51 + has to re-read fragments less often from disk, at the expense
52 + of extra system memory. Decreasing this amount will mean
53 + SquashFS uses less memory at the expense of extra reads from disk.
54 +
55 + Note there must be at least one cached fragment. Anything
56 + much more than three will probably not make much difference.
57 +
58 +config SQUASHFS_VMALLOC
59 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
60 + depends on SQUASHFS
61 + default n
62 + help
63 + By default SquashFS uses kmalloc to obtain fragment cache memory.
64 + Kmalloc memory is the standard kernel allocator, but it can fail
65 + on memory constrained systems. Because of the way Vmalloc works,
66 + Vmalloc can succeed when kmalloc fails. Specifying this option
67 + will make SquashFS always use Vmalloc to allocate the
68 + fragment cache memory.
69 +
70 + If unsure, say N.
71 +
72 config VXFS_FS
73 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
74 help
75 Index: linux-git/fs/Makefile
76 ===================================================================
77 --- linux-git.orig/fs/Makefile
78 +++ linux-git/fs/Makefile
79 @@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS) += ext3/ # Before
80 obj-$(CONFIG_JBD) += jbd/
81 obj-$(CONFIG_EXT2_FS) += ext2/
82 obj-$(CONFIG_CRAMFS) += cramfs/
83 +obj-$(CONFIG_SQUASHFS) += squashfs/
84 obj-$(CONFIG_RAMFS) += ramfs/
85 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
86 obj-$(CONFIG_CODA_FS) += coda/
87 Index: linux-git/fs/squashfs/inode.c
88 ===================================================================
89 --- /dev/null
90 +++ linux-git/fs/squashfs/inode.c
91 @@ -0,0 +1,1803 @@
92 +/*
93 + * Squashfs - a compressed read only filesystem for Linux
94 + *
95 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
96 + *
97 + * This program is free software; you can redistribute it and/or
98 + * modify it under the terms of the GNU General Public License
99 + * as published by the Free Software Foundation; either version 2,
100 + * or (at your option) any later version.
101 + *
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
106 + *
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
110 + *
111 + * inode.c
112 + */
113 +
114 +#define SQUASHFS_1_0_COMPATIBILITY
115 +
116 +#include <linux/types.h>
117 +#include <linux/squashfs_fs.h>
118 +#include <linux/module.h>
119 +#include <linux/errno.h>
120 +#include <linux/slab.h>
121 +#include <linux/fs.h>
122 +#include <linux/smp_lock.h>
123 +#include <linux/slab.h>
124 +#include <linux/squashfs_fs_sb.h>
125 +#include <linux/squashfs_fs_i.h>
126 +#include <linux/buffer_head.h>
127 +#include <linux/vfs.h>
128 +#include <linux/init.h>
129 +#include <linux/dcache.h>
130 +#include <asm/uaccess.h>
131 +#include <linux/wait.h>
132 +#include <asm/semaphore.h>
133 +#include <linux/zlib.h>
134 +#include <linux/blkdev.h>
135 +#include <linux/vmalloc.h>
136 +
137 +#ifdef SQUASHFS_TRACE
138 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
139 +#else
140 +#define TRACE(s, args...) {}
141 +#endif
142 +
143 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
144 +
145 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
146 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
147 +
148 +static void squashfs_put_super(struct super_block *);
149 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
150 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
151 +static int squashfs_readpage(struct file *file, struct page *page);
152 +static int squashfs_readpage4K(struct file *file, struct page *page);
153 +static int squashfs_readdir(struct file *, void *, filldir_t);
154 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *, struct nameidata *);
155 +static unsigned int read_data(struct super_block *s, char *buffer,
156 + unsigned int index, unsigned int length, unsigned int *next_index);
157 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
158 + unsigned int block, unsigned int offset, int length,
159 + unsigned int *next_block, unsigned int *next_offset);
160 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
161 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
162 + char *block_list, unsigned short **block_p, unsigned int *bsize);
163 +static void squashfs_put_super(struct super_block *s);
164 +static struct super_block *squashfs_get_sb(struct file_system_type *, int, const char *, void *);
165 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
166 +static void squashfs_destroy_inode(struct inode *inode);
167 +static int init_inodecache(void);
168 +static void destroy_inodecache(void);
169 +
170 +#ifdef SQUASHFS_1_0_COMPATIBILITY
171 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page);
172 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode);
173 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
174 + char *block_list, unsigned short **block_p, unsigned int *bsize);
175 +#endif
176 +
177 +DECLARE_MUTEX(read_data_mutex);
178 +
179 +static z_stream stream;
180 +
181 +static struct file_system_type squashfs_fs_type = {
182 + .owner = THIS_MODULE,
183 + .name = "squashfs",
184 + .get_sb = squashfs_get_sb,
185 + .kill_sb = kill_block_super,
186 + .fs_flags = FS_REQUIRES_DEV
187 + };
188 +
189 +static unsigned char squashfs_filetype_table[] = {
190 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
191 +};
192 +
193 +static struct super_operations squashfs_ops = {
194 + .alloc_inode = squashfs_alloc_inode,
195 + .destroy_inode = squashfs_destroy_inode,
196 + .statfs = squashfs_statfs,
197 + .put_super = squashfs_put_super,
198 +};
199 +
200 +static struct address_space_operations squashfs_symlink_aops = {
201 + .readpage = squashfs_symlink_readpage
202 +};
203 +
204 +static struct address_space_operations squashfs_aops = {
205 + .readpage = squashfs_readpage
206 +};
207 +
208 +static struct address_space_operations squashfs_aops_4K = {
209 + .readpage = squashfs_readpage4K
210 +};
211 +
212 +#ifdef SQUASHFS_1_0_COMPATIBILITY
213 +static struct address_space_operations squashfs_aops_lessthan4K = {
214 + .readpage = squashfs_readpage_lessthan4K
215 +};
216 +#endif
217 +
218 +static struct file_operations squashfs_dir_ops = {
219 + .read = generic_read_dir,
220 + .readdir = squashfs_readdir
221 +};
222 +
223 +static struct inode_operations squashfs_dir_inode_ops = {
224 + .lookup = squashfs_lookup
225 +};
226 +
227 +
228 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
229 +{
230 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
231 +}
232 +
233 +
234 +static struct buffer_head *get_block_length(struct super_block *s,
235 + int *cur_index, int *offset, int *c_byte)
236 +{
237 + squashfs_sb_info *msblk = s->s_fs_info;
238 + unsigned short temp;
239 + struct buffer_head *bh;
240 +
241 + if (!(bh = sb_bread(s, *cur_index)))
242 + goto out;
243 +
244 + if (msblk->devblksize - *offset == 1) {
245 + if (msblk->swap)
246 + ((unsigned char *) &temp)[1] = *((unsigned char *)
247 + (bh->b_data + *offset));
248 + else
249 + ((unsigned char *) &temp)[0] = *((unsigned char *)
250 + (bh->b_data + *offset));
251 + brelse(bh);
252 + if (!(bh = sb_bread(s, ++(*cur_index))))
253 + goto out;
254 + if (msblk->swap)
255 + ((unsigned char *) &temp)[0] = *((unsigned char *)
256 + bh->b_data);
257 + else
258 + ((unsigned char *) &temp)[1] = *((unsigned char *)
259 + bh->b_data);
260 + *c_byte = temp;
261 + *offset = 1;
262 + } else {
263 + if (msblk->swap) {
264 + ((unsigned char *) &temp)[1] = *((unsigned char *)
265 + (bh->b_data + *offset));
266 + ((unsigned char *) &temp)[0] = *((unsigned char *)
267 + (bh->b_data + *offset + 1));
268 + } else {
269 + ((unsigned char *) &temp)[0] = *((unsigned char *)
270 + (bh->b_data + *offset));
271 + ((unsigned char *) &temp)[1] = *((unsigned char *)
272 + (bh->b_data + *offset + 1));
273 + }
274 + *c_byte = temp;
275 + *offset += 2;
276 + }
277 +
278 + if (SQUASHFS_CHECK_DATA(msblk->sBlk.flags)) {
279 + if (*offset == msblk->devblksize) {
280 + brelse(bh);
281 + if (!(bh = sb_bread(s, ++(*cur_index))))
282 + goto out;
283 + *offset = 0;
284 + }
285 + if (*((unsigned char *) (bh->b_data + *offset)) !=
286 + SQUASHFS_MARKER_BYTE) {
287 + ERROR("Metadata block marker corrupt @ %x\n",
288 + *cur_index);
289 + brelse(bh);
290 + goto out;
291 + }
292 + (*offset)++;
293 + }
294 + return bh;
295 +
296 +out:
297 + return NULL;
298 +}
299 +
300 +
301 +static unsigned int read_data(struct super_block *s, char *buffer,
302 + unsigned int index, unsigned int length, unsigned int *next_index)
303 +{
304 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
305 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
306 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
307 + unsigned int cur_index = index >> msBlk->devblksize_log2;
308 + int bytes, avail_bytes, b = 0, k;
309 + char *c_buffer;
310 + unsigned int compressed;
311 + unsigned int c_byte = length;
312 +
313 + if(c_byte) {
314 + bytes = msBlk->devblksize - offset;
315 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
316 + c_buffer = compressed ? msBlk->read_data : buffer;
317 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
318 +
319 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
320 +
321 + if(!(bh[0] = sb_getblk(s, cur_index)))
322 + goto block_release;
323 + for(b = 1; bytes < c_byte; b++) {
324 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
325 + goto block_release;
326 + bytes += msBlk->devblksize;
327 + }
328 + ll_rw_block(READ, b, bh);
329 + } else {
330 + if(!(bh[0] = get_block_length(s, &cur_index, &offset, &c_byte)))
331 + goto read_failure;
332 +
333 + bytes = msBlk->devblksize - offset;
334 + compressed = SQUASHFS_COMPRESSED(c_byte);
335 + c_buffer = compressed ? msBlk->read_data : buffer;
336 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
337 +
338 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
339 +
340 + for(b = 1; bytes < c_byte; b++) {
341 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
342 + goto block_release;
343 + bytes += msBlk->devblksize;
344 + }
345 + ll_rw_block(READ, b - 1, bh + 1);
346 + }
347 +
348 + if(compressed)
349 + down(&read_data_mutex);
350 +
351 + for(bytes = 0, k = 0; k < b; k++) {
352 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
353 + wait_on_buffer(bh[k]);
354 + if (!buffer_uptodate(bh[k]))
355 + goto block_release;
356 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
357 + bytes += avail_bytes;
358 + offset = 0;
359 + brelse(bh[k]);
360 + }
361 +
362 + /*
363 + * uncompress block
364 + */
365 + if(compressed) {
366 + int zlib_err;
367 +
368 + stream.next_in = c_buffer;
369 + stream.avail_in = c_byte;
370 + stream.next_out = buffer;
371 + stream.avail_out = msBlk->read_size;
372 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
373 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
374 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
375 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
376 + bytes = 0;
377 + } else
378 + bytes = stream.total_out;
379 + up(&read_data_mutex);
380 + }
381 +
382 + if(next_index)
383 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
384 +
385 + return bytes;
386 +
387 +block_release:
388 + while(--b >= 0) brelse(bh[b]);
389 +
390 +read_failure:
391 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
392 + return 0;
393 +}
394 +
395 +
396 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
397 + unsigned int block, unsigned int offset, int length,
398 + unsigned int *next_block, unsigned int *next_offset)
399 +{
400 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
401 + int n, i, bytes, return_length = length;
402 + unsigned int next_index;
403 +
404 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
405 +
406 + for(;;) {
407 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
408 + if(msBlk->block_cache[i].block == block)
409 + break;
410 +
411 + down(&msBlk->block_cache_mutex);
412 + if(i == SQUASHFS_CACHED_BLKS) {
413 + /* read inode header block */
414 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
415 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
416 + break;
417 + if(n == 0) {
418 + wait_queue_t wait;
419 +
420 + init_waitqueue_entry(&wait, current);
421 + add_wait_queue(&msBlk->waitq, &wait);
422 + up(&msBlk->block_cache_mutex);
423 + set_current_state(TASK_UNINTERRUPTIBLE);
424 + schedule();
425 + set_current_state(TASK_RUNNING);
426 + remove_wait_queue(&msBlk->waitq, &wait);
427 + continue;
428 + }
429 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
430 +
431 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
432 + if(!(msBlk->block_cache[i].data = (unsigned char *)
433 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
434 + ERROR("Failed to allocate cache block\n");
435 + up(&msBlk->block_cache_mutex);
436 + return 0;
437 + }
438 + }
439 +
440 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
441 + up(&msBlk->block_cache_mutex);
442 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
443 + &next_index))) {
444 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
445 + return 0;
446 + }
447 + down(&msBlk->block_cache_mutex);
448 + wake_up(&msBlk->waitq);
449 + msBlk->block_cache[i].block = block;
450 + msBlk->block_cache[i].next_index = next_index;
451 + TRACE("Read cache block [%x:%x]\n", block, offset);
452 + }
453 +
454 + if(msBlk->block_cache[i].block != block) {
455 + up(&msBlk->block_cache_mutex);
456 + continue;
457 + }
458 +
459 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
460 + if(buffer)
461 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
462 + if(msBlk->block_cache[i].length - offset == length) {
463 + *next_block = msBlk->block_cache[i].next_index;
464 + *next_offset = 0;
465 + } else {
466 + *next_block = block;
467 + *next_offset = offset + length;
468 + }
469 +
470 + up(&msBlk->block_cache_mutex);
471 + return return_length;
472 + } else {
473 + if(buffer) {
474 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
475 + buffer += bytes;
476 + }
477 + block = msBlk->block_cache[i].next_index;
478 + up(&msBlk->block_cache_mutex);
479 + length -= bytes;
480 + offset = 0;
481 + }
482 + }
483 +}
484 +
485 +
486 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
487 +{
488 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
489 + unsigned int start_block = msBlk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
490 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
491 + squashfs_fragment_entry fragment_entry;
492 +
493 + if(msBlk->swap) {
494 + squashfs_fragment_entry sfragment_entry;
495 +
496 + if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
497 + sizeof(sfragment_entry), &start_block, &offset))
498 + return 0;
499 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
500 + } else
501 + if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
502 + sizeof(fragment_entry), &start_block, &offset))
503 + return 0;
504 +
505 + *fragment_start_block = fragment_entry.start_block;
506 + *fragment_size = fragment_entry.size;
507 +
508 + return 1;
509 +}
510 +
511 +
512 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
513 +{
514 + down(&msBlk->fragment_mutex);
515 + fragment->locked --;
516 + wake_up(&msBlk->fragment_wait_queue);
517 + up(&msBlk->fragment_mutex);
518 +}
519 +
520 +
521 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
522 +{
523 + int i, n;
524 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
525 +
526 + for(;;) {
527 + down(&msBlk->fragment_mutex);
528 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS && msBlk->fragment[i].block != start_block; i++);
529 + if(i == SQUASHFS_CACHED_FRAGMENTS) {
530 + for(i = msBlk->next_fragment, n = SQUASHFS_CACHED_FRAGMENTS;
531 + n && msBlk->fragment[i].locked; n--, i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS);
532 +
533 + if(n == 0) {
534 + wait_queue_t wait;
535 +
536 + init_waitqueue_entry(&wait, current);
537 + add_wait_queue(&msBlk->fragment_wait_queue, &wait);
538 + up(&msBlk->fragment_mutex);
539 + set_current_state(TASK_UNINTERRUPTIBLE);
540 + schedule();
541 + set_current_state(TASK_RUNNING);
542 + remove_wait_queue(&msBlk->fragment_wait_queue, &wait);
543 + continue;
544 + }
545 + msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
546 +
547 + if(msBlk->fragment[i].data == NULL)
548 + if(!(msBlk->fragment[i].data = (unsigned char *)
549 + SQUASHFS_ALLOC(SQUASHFS_FILE_MAX_SIZE))) {
550 + ERROR("Failed to allocate fragment cache block\n");
551 + up(&msBlk->fragment_mutex);
552 + return NULL;
553 + }
554 +
555 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
556 + msBlk->fragment[i].locked = 1;
557 + up(&msBlk->fragment_mutex);
558 + if(!(msBlk->fragment[i].length = read_data(s, msBlk->fragment[i].data, start_block, length,
559 + NULL))) {
560 + ERROR("Unable to read fragment cache block [%x]\n", start_block);
561 + msBlk->fragment[i].locked = 0;
562 + return NULL;
563 + }
564 + msBlk->fragment[i].block = start_block;
565 + TRACE("New fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
566 + return &msBlk->fragment[i];
567 + }
568 +
569 + msBlk->fragment[i].locked ++;
570 + up(&msBlk->fragment_mutex);
571 +
572 + TRACE("Got fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
573 + return &msBlk->fragment[i];
574 + }
575 +}
576 +
577 +
578 +#ifdef SQUASHFS_1_0_COMPATIBILITY
579 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
580 +{
581 + struct inode *i = new_inode(s);
582 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
583 + squashfs_super_block *sBlk = &msBlk->sBlk;
584 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
585 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
586 + unsigned int next_block, next_offset;
587 + squashfs_base_inode_header_1 inodeb;
588 +
589 + TRACE("Entered squashfs_iget_1\n");
590 +
591 + if(msBlk->swap) {
592 + squashfs_base_inode_header_1 sinodeb;
593 +
594 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
595 + sizeof(sinodeb), &next_block, &next_offset))
596 + goto failed_read;
597 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
598 + } else
599 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
600 + sizeof(inodeb), &next_block, &next_offset))
601 + goto failed_read;
602 +
603 + i->i_nlink = 1;
604 +
605 + i->i_mtime.tv_sec = sBlk->mkfs_time;
606 + i->i_atime.tv_sec = sBlk->mkfs_time;
607 + i->i_ctime.tv_sec = sBlk->mkfs_time;
608 +
609 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
610 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
611 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
612 +
613 + i->i_mode = inodeb.mode;
614 +
615 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
616 + case SQUASHFS_FILE_TYPE: {
617 + squashfs_reg_inode_header_1 inodep;
618 +
619 + if(msBlk->swap) {
620 + squashfs_reg_inode_header_1 sinodep;
621 +
622 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
623 + &next_block, &next_offset))
624 + goto failed_read;
625 + SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
626 + } else
627 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
628 + &next_block, &next_offset))
629 + goto failed_read;
630 +
631 + i->i_size = inodep.file_size;
632 + i->i_fop = &generic_ro_fops;
633 + if(sBlk->block_size > 4096)
634 + i->i_data.a_ops = &squashfs_aops;
635 + else if(sBlk->block_size == 4096)
636 + i->i_data.a_ops = &squashfs_aops_4K;
637 + else
638 + i->i_data.a_ops = &squashfs_aops_lessthan4K;
639 + i->i_mode |= S_IFREG;
640 + i->i_mtime.tv_sec = inodep.mtime;
641 + i->i_atime.tv_sec = inodep.mtime;
642 + i->i_ctime.tv_sec = inodep.mtime;
643 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
644 + i->i_blksize = PAGE_CACHE_SIZE;
645 + SQUASHFS_I(i)->u.s1.fragment_start_block = SQUASHFS_INVALID_BLK;
646 + SQUASHFS_I(i)->u.s1.fragment_offset = 0;
647 + SQUASHFS_I(i)->start_block = inodep.start_block;
648 + SQUASHFS_I(i)->block_list_start = next_block;
649 + SQUASHFS_I(i)->offset = next_offset;
650 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
651 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
652 + break;
653 + }
654 + case SQUASHFS_DIR_TYPE: {
655 + squashfs_dir_inode_header_1 inodep;
656 +
657 + if(msBlk->swap) {
658 + squashfs_dir_inode_header_1 sinodep;
659 +
660 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
661 + &next_block, &next_offset))
662 + goto failed_read;
663 + SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
664 + } else
665 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
666 + &next_block, &next_offset))
667 + goto failed_read;
668 +
669 + i->i_size = inodep.file_size;
670 + i->i_op = &squashfs_dir_inode_ops;
671 + i->i_fop = &squashfs_dir_ops;
672 + i->i_mode |= S_IFDIR;
673 + i->i_mtime.tv_sec = inodep.mtime;
674 + i->i_atime.tv_sec = inodep.mtime;
675 + i->i_ctime.tv_sec = inodep.mtime;
676 + SQUASHFS_I(i)->start_block = inodep.start_block;
677 + SQUASHFS_I(i)->offset = inodep.offset;
678 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
679 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
680 + inodep.start_block, inodep.offset);
681 + break;
682 + }
683 + case SQUASHFS_SYMLINK_TYPE: {
684 + squashfs_symlink_inode_header_1 inodep;
685 +
686 + if(msBlk->swap) {
687 + squashfs_symlink_inode_header_1 sinodep;
688 +
689 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
690 + &next_block, &next_offset))
691 + goto failed_read;
692 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
693 + } else
694 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
695 + &next_block, &next_offset))
696 + goto failed_read;
697 +
698 + i->i_size = inodep.symlink_size;
699 + i->i_op = &page_symlink_inode_operations;
700 + i->i_data.a_ops = &squashfs_symlink_aops;
701 + i->i_mode |= S_IFLNK;
702 + SQUASHFS_I(i)->start_block = next_block;
703 + SQUASHFS_I(i)->offset = next_offset;
704 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
705 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
706 + break;
707 + }
708 + case SQUASHFS_BLKDEV_TYPE:
709 + case SQUASHFS_CHRDEV_TYPE: {
710 + squashfs_dev_inode_header_1 inodep;
711 +
712 + if(msBlk->swap) {
713 + squashfs_dev_inode_header_1 sinodep;
714 +
715 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
716 + &next_block, &next_offset))
717 + goto failed_read;
718 + SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
719 + } else
720 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
721 + &next_block, &next_offset))
722 + goto failed_read;
723 +
724 + i->i_size = 0;
725 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
726 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
727 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
728 + break;
729 + }
730 + case SQUASHFS_IPC_TYPE: {
731 + squashfs_ipc_inode_header_1 inodep;
732 +
733 + if(msBlk->swap) {
734 + squashfs_ipc_inode_header_1 sinodep;
735 +
736 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
737 + &next_block, &next_offset))
738 + goto failed_read;
739 + SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
740 + } else
741 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
742 + &next_block, &next_offset))
743 + goto failed_read;
744 +
745 + i->i_size = 0;
746 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
747 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
748 + init_special_inode(i, i->i_mode, 0);
749 + break;
750 + }
751 + default:
752 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
753 + goto failed_read1;
754 + }
755 +
756 + if(inodeb.guid == 15)
757 + i->i_gid = i->i_uid;
758 + else
759 + i->i_gid = msBlk->guid[inodeb.guid];
760 +
761 + insert_inode_hash(i);
762 + return i;
763 +
764 +failed_read:
765 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
766 +
767 +failed_read1:
768 + return NULL;
769 +}
770 +#endif
771 +
772 +
773 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
774 +{
775 + struct inode *i = new_inode(s);
776 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
777 + squashfs_super_block *sBlk = &msBlk->sBlk;
778 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
779 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
780 + unsigned int next_block, next_offset;
781 + squashfs_base_inode_header inodeb;
782 +
783 + TRACE("Entered squashfs_iget\n");
784 +
785 + if(msBlk->swap) {
786 + squashfs_base_inode_header sinodeb;
787 +
788 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
789 + sizeof(sinodeb), &next_block, &next_offset))
790 + goto failed_read;
791 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
792 + } else
793 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
794 + sizeof(inodeb), &next_block, &next_offset))
795 + goto failed_read;
796 +
797 + i->i_nlink = 1;
798 +
799 + i->i_mtime.tv_sec = sBlk->mkfs_time;
800 + i->i_atime.tv_sec = sBlk->mkfs_time;
801 + i->i_ctime.tv_sec = sBlk->mkfs_time;
802 +
803 + i->i_uid = msBlk->uid[inodeb.uid];
804 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
805 +
806 + i->i_mode = inodeb.mode;
807 +
808 + switch(inodeb.inode_type) {
809 + case SQUASHFS_FILE_TYPE: {
810 + squashfs_reg_inode_header inodep;
811 +
812 + if(msBlk->swap) {
813 + squashfs_reg_inode_header sinodep;
814 +
815 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
816 + &next_block, &next_offset))
817 + goto failed_read;
818 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
819 + } else
820 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
821 + &next_block, &next_offset))
822 + goto failed_read;
823 +
824 + SQUASHFS_I(i)->u.s1.fragment_start_block = SQUASHFS_INVALID_BLK;
825 + if(inodep.fragment != SQUASHFS_INVALID_BLK && !get_fragment_location(s, inodep.fragment,
826 + &SQUASHFS_I(i)->u.s1.fragment_start_block, &SQUASHFS_I(i)->u.s1.fragment_size))
827 + goto failed_read;
828 +
829 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep.offset;
830 + i->i_size = inodep.file_size;
831 + i->i_fop = &generic_ro_fops;
832 + if(sBlk->block_size > 4096)
833 + i->i_data.a_ops = &squashfs_aops;
834 + else
835 + i->i_data.a_ops = &squashfs_aops_4K;
836 + i->i_mode |= S_IFREG;
837 + i->i_mtime.tv_sec = inodep.mtime;
838 + i->i_atime.tv_sec = inodep.mtime;
839 + i->i_ctime.tv_sec = inodep.mtime;
840 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
841 + i->i_blksize = PAGE_CACHE_SIZE;
842 + SQUASHFS_I(i)->start_block = inodep.start_block;
843 + SQUASHFS_I(i)->block_list_start = next_block;
844 + SQUASHFS_I(i)->offset = next_offset;
845 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
846 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
847 + break;
848 + }
849 + case SQUASHFS_DIR_TYPE: {
850 + squashfs_dir_inode_header inodep;
851 +
852 + if(msBlk->swap) {
853 + squashfs_dir_inode_header sinodep;
854 +
855 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
856 + &next_block, &next_offset))
857 + goto failed_read;
858 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
859 + } else
860 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
861 + &next_block, &next_offset))
862 + goto failed_read;
863 +
864 + i->i_size = inodep.file_size;
865 + i->i_op = &squashfs_dir_inode_ops;
866 + i->i_fop = &squashfs_dir_ops;
867 + i->i_mode |= S_IFDIR;
868 + i->i_mtime.tv_sec = inodep.mtime;
869 + i->i_atime.tv_sec = inodep.mtime;
870 + i->i_ctime.tv_sec = inodep.mtime;
871 + SQUASHFS_I(i)->start_block = inodep.start_block;
872 + SQUASHFS_I(i)->offset = inodep.offset;
873 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
874 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
875 + inodep.start_block, inodep.offset);
876 + break;
877 + }
878 + case SQUASHFS_LDIR_TYPE: {
879 + squashfs_ldir_inode_header inodep;
880 +
881 + if(msBlk->swap) {
882 + squashfs_ldir_inode_header sinodep;
883 +
884 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
885 + &next_block, &next_offset))
886 + goto failed_read;
887 + SQUASHFS_SWAP_LDIR_INODE_HEADER(&inodep, &sinodep);
888 + } else
889 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
890 + &next_block, &next_offset))
891 + goto failed_read;
892 +
893 + i->i_size = inodep.file_size;
894 + i->i_op = &squashfs_dir_inode_ops;
895 + i->i_fop = &squashfs_dir_ops;
896 + i->i_mode |= S_IFDIR;
897 + i->i_mtime.tv_sec = inodep.mtime;
898 + i->i_atime.tv_sec = inodep.mtime;
899 + i->i_ctime.tv_sec = inodep.mtime;
900 + SQUASHFS_I(i)->start_block = inodep.start_block;
901 + SQUASHFS_I(i)->offset = inodep.offset;
902 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
903 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
904 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep.i_count;
905 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
906 + inodep.start_block, inodep.offset);
907 + break;
908 + }
909 + case SQUASHFS_SYMLINK_TYPE: {
910 + squashfs_symlink_inode_header inodep;
911 +
912 + if(msBlk->swap) {
913 + squashfs_symlink_inode_header sinodep;
914 +
915 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
916 + &next_block, &next_offset))
917 + goto failed_read;
918 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
919 + } else
920 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
921 + &next_block, &next_offset))
922 + goto failed_read;
923 +
924 + i->i_size = inodep.symlink_size;
925 + i->i_op = &page_symlink_inode_operations;
926 + i->i_data.a_ops = &squashfs_symlink_aops;
927 + i->i_mode |= S_IFLNK;
928 + SQUASHFS_I(i)->start_block = next_block;
929 + SQUASHFS_I(i)->offset = next_offset;
930 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
931 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
932 + break;
933 + }
934 + case SQUASHFS_BLKDEV_TYPE:
935 + case SQUASHFS_CHRDEV_TYPE: {
936 + squashfs_dev_inode_header inodep;
937 +
938 + if(msBlk->swap) {
939 + squashfs_dev_inode_header sinodep;
940 +
941 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
942 + &next_block, &next_offset))
943 + goto failed_read;
944 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
945 + } else
946 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
947 + &next_block, &next_offset))
948 + goto failed_read;
949 +
950 + i->i_size = 0;
951 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
952 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
953 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
954 + break;
955 + }
956 + case SQUASHFS_FIFO_TYPE:
957 + case SQUASHFS_SOCKET_TYPE: {
958 + i->i_size = 0;
959 + i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
960 + init_special_inode(i, i->i_mode, 0);
961 + break;
962 + }
963 + default:
964 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
965 + goto failed_read1;
966 + }
967 +
968 + if(inodeb.guid == SQUASHFS_GUIDS)
969 + i->i_gid = i->i_uid;
970 + else
971 + i->i_gid = msBlk->guid[inodeb.guid];
972 +
973 + insert_inode_hash(i);
974 + return i;
975 +
976 +failed_read:
977 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
978 +
979 +failed_read1:
980 + return NULL;
981 +}
982 +
983 +
984 +static int squashfs_fill_super(struct super_block *s,
985 + void *data, int silent)
986 +{
987 + squashfs_sb_info *msBlk;
988 + squashfs_super_block *sBlk;
989 + int i;
990 + char b[BDEVNAME_SIZE];
991 +
992 + TRACE("Entered squashfs_read_superblock\n");
993 +
994 + if(!(s->s_fs_info = (void *) kmalloc(sizeof(squashfs_sb_info), GFP_KERNEL))) {
995 + ERROR("Failed to allocate superblock\n");
996 + return -ENOMEM;
997 + }
998 + msBlk = (squashfs_sb_info *) s->s_fs_info;
999 + sBlk = &msBlk->sBlk;
1000 +
1001 + msBlk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1002 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
1003 +
1004 + init_MUTEX(&msBlk->read_page_mutex);
1005 + init_MUTEX(&msBlk->block_cache_mutex);
1006 + init_MUTEX(&msBlk->fragment_mutex);
1007 +
1008 + init_waitqueue_head(&msBlk->waitq);
1009 + init_waitqueue_head(&msBlk->fragment_wait_queue);
1010 +
1011 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1012 + SERROR("unable to read superblock\n");
1013 + goto failed_mount;
1014 + }
1015 +
1016 + /* Check it is a SQUASHFS superblock */
1017 + msBlk->swap = 0;
1018 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
1019 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
1020 + squashfs_super_block sblk;
1021 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(s->s_bdev, b));
1022 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
1023 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
1024 + msBlk->swap = 1;
1025 + } else {
1026 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(s->s_bdev, b));
1027 + goto failed_mount;
1028 + }
1029 + }
1030 +
1031 + /* Check the MAJOR & MINOR versions */
1032 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1033 + if((sBlk->s_major != 1) && (sBlk->s_major != 2 || sBlk->s_minor > SQUASHFS_MINOR)) {
1034 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (1 : x) or (2 : <= %d)\n",
1035 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MINOR);
1036 + goto failed_mount;
1037 + }
1038 + if(sBlk->s_major == 1)
1039 + sBlk->block_size = sBlk->block_size_1;
1040 +#else
1041 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
1042 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
1043 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
1044 + goto failed_mount;
1045 + }
1046 +#endif
1047 +
1048 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1049 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
1050 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
1051 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
1052 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
1053 + TRACE("Block size %d\n", sBlk->block_size);
1054 + TRACE("Number of inodes %d\n", sBlk->inodes);
1055 + if(sBlk->s_major > 1)
1056 + TRACE("Number of fragments %d\n", sBlk->fragments);
1057 + TRACE("Number of uids %d\n", sBlk->no_uids);
1058 + TRACE("Number of gids %d\n", sBlk->no_guids);
1059 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
1060 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
1061 + if(sBlk->s_major > 1)
1062 + TRACE("sBlk->fragment_table_start %x\n", sBlk->fragment_table_start);
1063 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
1064 +
1065 + s->s_flags |= MS_RDONLY;
1066 + s->s_op = &squashfs_ops;
1067 +
1068 + /* Init inode_table block pointer array */
1069 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1070 + ERROR("Failed to allocate block cache\n");
1071 + goto failed_mount;
1072 + }
1073 +
1074 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1075 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1076 +
1077 + msBlk->next_cache = 0;
1078 +
1079 + /* Allocate read_data block */
1080 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
1081 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
1082 + ERROR("Failed to allocate read_data block\n");
1083 + goto failed_mount1;
1084 + }
1085 +
1086 + /* Allocate read_page block */
1087 + if(sBlk->block_size > PAGE_CACHE_SIZE) {
1088 + if(!(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
1089 + ERROR("Failed to allocate read_page block\n");
1090 + goto failed_mount2;
1091 + }
1092 + } else
1093 + msBlk->read_page = NULL;
1094 +
1095 + /* Allocate uid and gid tables */
1096 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
1097 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
1098 + ERROR("Failed to allocate uid/gid table\n");
1099 + goto failed_mount3;
1100 + }
1101 + msBlk->guid = msBlk->uid + sBlk->no_uids;
1102 +
1103 + if(msBlk->swap) {
1104 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1105 +
1106 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1107 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1108 + SERROR("unable to read uid/gid table\n");
1109 + goto failed_mount4;
1110 + }
1111 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1112 + } else
1113 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1114 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1115 + SERROR("unable to read uid/gid table\n");
1116 + goto failed_mount4;
1117 + }
1118 +
1119 +
1120 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1121 + if(sBlk->s_major == 1) {
1122 + msBlk->iget = squashfs_iget_1;
1123 + msBlk->read_blocklist = read_blocklist_1;
1124 + msBlk->fragment = NULL;
1125 + msBlk->fragment_index = NULL;
1126 + goto allocate_root;
1127 + }
1128 +#endif
1129 + msBlk->iget = squashfs_iget;
1130 + msBlk->read_blocklist = read_blocklist;
1131 +
1132 + if(!(msBlk->fragment = (struct squashfs_fragment_cache *) kmalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1133 + ERROR("Failed to allocate fragment block cache\n");
1134 + goto failed_mount4;
1135 + }
1136 +
1137 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1138 + msBlk->fragment[i].locked = 0;
1139 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
1140 + msBlk->fragment[i].data = NULL;
1141 + }
1142 +
1143 + msBlk->next_fragment = 0;
1144 +
1145 + /* Allocate fragment index table */
1146 + if(!(msBlk->fragment_index = (squashfs_fragment_index *) kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), GFP_KERNEL))) {
1147 + ERROR("Failed to allocate uid/gid table\n");
1148 + goto failed_mount5;
1149 + }
1150 +
1151 + if(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) &&
1152 + !read_data(s, (char *) msBlk->fragment_index, sBlk->fragment_table_start,
1153 + SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1154 + SERROR("unable to read fragment index table\n");
1155 + goto failed_mount6;
1156 + }
1157 +
1158 + if(msBlk->swap) {
1159 + int i;
1160 + squashfs_fragment_index fragment;
1161 +
1162 + for(i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments); i++) {
1163 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment), &msBlk->fragment_index[i], 1);
1164 + msBlk->fragment_index[i] = fragment;
1165 + }
1166 + }
1167 +
1168 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1169 +allocate_root:
1170 +#endif
1171 + if(!(s->s_root = d_alloc_root((msBlk->iget)(s, sBlk->root_inode)))) {
1172 + ERROR("Root inode create failed\n");
1173 + goto failed_mount5;
1174 + }
1175 +
1176 + TRACE("Leaving squashfs_read_super\n");
1177 + return 0;
1178 +
1179 +failed_mount6:
1180 + kfree(msBlk->fragment_index);
1181 +failed_mount5:
1182 + kfree(msBlk->fragment);
1183 +failed_mount4:
1184 + kfree(msBlk->uid);
1185 +failed_mount3:
1186 + kfree(msBlk->read_page);
1187 +failed_mount2:
1188 + kfree(msBlk->read_data);
1189 +failed_mount1:
1190 + kfree(msBlk->block_cache);
1191 +failed_mount:
1192 + kfree(s->s_fs_info);
1193 + s->s_fs_info = NULL;
1194 + return -EINVAL;
1195 +}
1196 +
1197 +
1198 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1199 +{
1200 + squashfs_super_block *sBlk = &((squashfs_sb_info *)s->s_fs_info)->sBlk;
1201 +
1202 + TRACE("Entered squashfs_statfs\n");
1203 + buf->f_type = SQUASHFS_MAGIC;
1204 + buf->f_bsize = sBlk->block_size;
1205 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
1206 + buf->f_bfree = buf->f_bavail = 0;
1207 + buf->f_files = sBlk->inodes;
1208 + buf->f_ffree = 0;
1209 + buf->f_namelen = SQUASHFS_NAME_LEN;
1210 + return 0;
1211 +}
1212 +
1213 +
1214 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1215 +{
1216 + struct inode *inode = page->mapping->host;
1217 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1218 + unsigned int block = SQUASHFS_I(inode)->start_block;
1219 + int offset = SQUASHFS_I(inode)->offset;
1220 + void *pageaddr = kmap(page);
1221 +
1222 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
1223 + page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(inode)->offset);
1224 +
1225 + for(length = 0; length < index; length += bytes) {
1226 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
1227 + PAGE_CACHE_SIZE, &block, &offset))) {
1228 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1229 + goto skip_read;
1230 + }
1231 + }
1232 +
1233 + if(length != index) {
1234 + ERROR("(squashfs_symlink_readpage) length != index\n");
1235 + bytes = 0;
1236 + goto skip_read;
1237 + }
1238 +
1239 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
1240 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
1241 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1242 +
1243 +skip_read:
1244 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1245 + kunmap(page);
1246 + flush_dcache_page(page);
1247 + SetPageUptodate(page);
1248 + unlock_page(page);
1249 +
1250 + return 0;
1251 +}
1252 +
1253 +
1254 +#define SIZE 256
1255 +
1256 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1257 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
1258 + char *block_list, unsigned short **block_p, unsigned int *bsize)
1259 +{
1260 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1261 + unsigned short *block_listp;
1262 + int i = 0;
1263 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1264 + int offset = SQUASHFS_I(inode)->offset;
1265 + unsigned int block = SQUASHFS_I(inode)->start_block;
1266 +
1267 + for(;;) {
1268 + int blocks = (index + readahead_blks - i);
1269 + if(blocks > (SIZE >> 1)) {
1270 + if((index - i) <= (SIZE >> 1))
1271 + blocks = index - i;
1272 + else
1273 + blocks = SIZE >> 1;
1274 + }
1275 +
1276 + if(msBlk->swap) {
1277 + unsigned char sblock_list[SIZE];
1278 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1279 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1280 + return 0;
1281 + }
1282 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1283 + } else
1284 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1285 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1286 + return 0;
1287 + }
1288 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1289 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1290 + if(blocks >= readahead_blks)
1291 + break;
1292 + }
1293 +
1294 + if(bsize)
1295 + *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1296 + else
1297 + *block_p = block_listp;
1298 + return block;
1299 +}
1300 +#endif
1301 +
1302 +
1303 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1304 + char *block_list, unsigned short **block_p, unsigned int *bsize)
1305 +{
1306 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1307 + unsigned int *block_listp;
1308 + int i = 0;
1309 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1310 + int offset = SQUASHFS_I(inode)->offset;
1311 + unsigned int block = SQUASHFS_I(inode)->start_block;
1312 +
1313 + for(;;) {
1314 + int blocks = (index + readahead_blks - i);
1315 + if(blocks > (SIZE >> 2)) {
1316 + if((index - i) <= (SIZE >> 2))
1317 + blocks = index - i;
1318 + else
1319 + blocks = SIZE >> 2;
1320 + }
1321 +
1322 + if(msBlk->swap) {
1323 + unsigned char sblock_list[SIZE];
1324 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1325 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1326 + return 0;
1327 + }
1328 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1329 + } else
1330 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1331 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1332 + return 0;
1333 + }
1334 + for(block_listp = (unsigned int *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1335 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1336 + if(blocks >= readahead_blks)
1337 + break;
1338 + }
1339 +
1340 + *bsize = *block_listp;
1341 + return block;
1342 +}
1343 +
1344 +
1345 +static int squashfs_readpage(struct file *file, struct page *page)
1346 +{
1347 + struct inode *inode = page->mapping->host;
1348 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1349 + squashfs_super_block *sBlk = &msBlk->sBlk;
1350 + unsigned char block_list[SIZE];
1351 + unsigned int bsize, block, i = 0, bytes = 0, byte_offset = 0;
1352 + int index = page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT);
1353 + void *pageaddr = kmap(page);
1354 + struct squashfs_fragment_cache *fragment = NULL;
1355 + char *data_ptr = msBlk->read_page;
1356 +
1357 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1358 + int start_index = page->index & ~mask;
1359 + int end_index = start_index | mask;
1360 +
1361 + TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1362 + SQUASHFS_I(inode)->start_block);
1363 +
1364 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)) {
1365 + goto skip_read;
1366 + }
1367 +
1368 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log)) {
1369 + if((block = (msBlk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize)) == 0)
1370 + goto skip_read;
1371 +
1372 + down(&msBlk->read_page_mutex);
1373 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, bsize, NULL))) {
1374 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1375 + up(&msBlk->read_page_mutex);
1376 + goto skip_read;
1377 + }
1378 + } else {
1379 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->u.s1.fragment_start_block, SQUASHFS_I(inode)->u.s1.fragment_size)) == NULL) {
1380 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->u.s1.fragment_start_block, (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1381 + goto skip_read;
1382 + }
1383 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset + (inode->i_size & (sBlk->block_size - 1));
1384 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1385 + data_ptr = fragment->data;
1386 + }
1387 +
1388 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1389 + struct page *push_page;
1390 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1391 +
1392 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1393 +
1394 + if(i == page->index) {
1395 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1396 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1397 + kunmap(page);
1398 + flush_dcache_page(page);
1399 + SetPageUptodate(page);
1400 + unlock_page(page);
1401 + } else if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1402 + void *pageaddr = kmap(push_page);
1403 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1404 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1405 + kunmap(push_page);
1406 + flush_dcache_page(push_page);
1407 + SetPageUptodate(push_page);
1408 + unlock_page(push_page);
1409 + page_cache_release(push_page);
1410 + }
1411 + }
1412 +
1413 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log))
1414 + up(&msBlk->read_page_mutex);
1415 + else
1416 + release_cached_fragment(msBlk, fragment);
1417 +
1418 + return 0;
1419 +
1420 +skip_read:
1421 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1422 + kunmap(page);
1423 + flush_dcache_page(page);
1424 + SetPageUptodate(page);
1425 + unlock_page(page);
1426 +
1427 + return 0;
1428 +}
1429 +
1430 +
1431 +static int squashfs_readpage4K(struct file *file, struct page *page)
1432 +{
1433 + struct inode *inode = page->mapping->host;
1434 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1435 + squashfs_super_block *sBlk = &msBlk->sBlk;
1436 + unsigned char block_list[SIZE];
1437 + unsigned int bsize, block, bytes = 0;
1438 + void *pageaddr = kmap(page);
1439 +
1440 + TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1441 + SQUASHFS_I(inode)->start_block);
1442 +
1443 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)) {
1444 + goto skip_read;
1445 + }
1446 +
1447 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || page->index < (inode->i_size >> sBlk->block_log)) {
1448 + block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1449 +
1450 + if(!(bytes = read_data(inode->i_sb, pageaddr, block, bsize, NULL)))
1451 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1452 + } else {
1453 + struct squashfs_fragment_cache *fragment;
1454 +
1455 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->u.s1.fragment_start_block, SQUASHFS_I(inode)->u.s1.fragment_size)) == NULL)
1456 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->u.s1.fragment_start_block, (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1457 + else {
1458 + bytes = inode->i_size & (sBlk->block_size - 1);
1459 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset, bytes);
1460 + release_cached_fragment(msBlk, fragment);
1461 + }
1462 + }
1463 +
1464 +skip_read:
1465 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1466 + kunmap(page);
1467 + flush_dcache_page(page);
1468 + SetPageUptodate(page);
1469 + unlock_page(page);
1470 +
1471 + return 0;
1472 +}
1473 +
1474 +
1475 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1476 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1477 +{
1478 + struct inode *inode = page->mapping->host;
1479 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1480 + squashfs_super_block *sBlk = &msBlk->sBlk;
1481 + unsigned char block_list[SIZE];
1482 + unsigned short *block_listp, block, bytes = 0;
1483 + int index = page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
1484 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
1485 + int readahead_blks = 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
1486 + void *pageaddr = kmap(page);
1487 +
1488 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1489 + int byte;
1490 +
1491 + TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1492 + SQUASHFS_I(inode)->start_block);
1493 +
1494 + block = read_blocklist_1(inode, index, readahead_blks, block_list, &block_listp, NULL);
1495 +
1496 + if(i_end > file_blocks)
1497 + i_end = file_blocks;
1498 +
1499 + while(index < i_end) {
1500 + int c_byte = !SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_SIZE(*block_listp) | SQUASHFS_COMPRESSED_BIT_BLOCK : *block_listp;
1501 + if(!(byte = read_data(inode->i_sb, pageaddr, block, c_byte, NULL))) {
1502 + ERROR("Unable to read page, block %x, size %x\n", block, *block_listp);
1503 + goto skip_read;
1504 + }
1505 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1506 + pageaddr += byte;
1507 + bytes += byte;
1508 + index ++;
1509 + block_listp ++;
1510 + }
1511 +
1512 +skip_read:
1513 + memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1514 + kunmap(page);
1515 + flush_dcache_page(page);
1516 + SetPageUptodate(page);
1517 + unlock_page(page);
1518 +
1519 + return 0;
1520 +}
1521 +#endif
1522 +
1523 +
1524 +static int get_dir_index_using_offset(struct super_block *s, unsigned int *next_block,
1525 + unsigned int *next_offset, unsigned int index_start, unsigned int index_offset,
1526 + int i_count, long long f_pos)
1527 +{
1528 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
1529 + squashfs_super_block *sBlk = &msBlk->sBlk;
1530 + int i, length = 0;
1531 + squashfs_dir_index index;
1532 +
1533 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n", i_count, (unsigned int) f_pos);
1534 +
1535 + if(f_pos == 0)
1536 + return 0;
1537 +
1538 + for(i = 0; i < i_count; i++) {
1539 + if(msBlk->swap) {
1540 + squashfs_dir_index sindex;
1541 + squashfs_get_cached_block(s, (char *) &sindex, index_start, index_offset,
1542 + sizeof(sindex), &index_start, &index_offset);
1543 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1544 + } else
1545 + squashfs_get_cached_block(s, (char *) &index, index_start, index_offset,
1546 + sizeof(index), &index_start, &index_offset);
1547 +
1548 + if(index.index > f_pos)
1549 + break;
1550 +
1551 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1552 + index.size + 1, &index_start, &index_offset);
1553 +
1554 + length = index.index;
1555 + *next_block = index.start_block + sBlk->directory_table_start;
1556 + }
1557 +
1558 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1559 + return length;
1560 +}
1561 +
1562 +
1563 +static int get_dir_index_using_name(struct super_block *s, unsigned int *next_block,
1564 + unsigned int *next_offset, unsigned int index_start, unsigned int index_offset,
1565 + int i_count, const char *name, int size)
1566 +{
1567 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
1568 + squashfs_super_block *sBlk = &msBlk->sBlk;
1569 + int i, length = 0;
1570 + char buffer[sizeof(squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1571 + squashfs_dir_index *index = (squashfs_dir_index *) buffer;
1572 + char str[SQUASHFS_NAME_LEN + 1];
1573 +
1574 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1575 +
1576 + strncpy(str, name, size);
1577 + str[size] = '\0';
1578 +
1579 + for(i = 0; i < i_count; i++) {
1580 + if(msBlk->swap) {
1581 + squashfs_dir_index sindex;
1582 + squashfs_get_cached_block(s, (char *) &sindex, index_start, index_offset,
1583 + sizeof(sindex), &index_start, &index_offset);
1584 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1585 + } else
1586 + squashfs_get_cached_block(s, (char *) index, index_start, index_offset,
1587 + sizeof(squashfs_dir_index), &index_start, &index_offset);
1588 +
1589 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1590 + index->size + 1, &index_start, &index_offset);
1591 +
1592 + index->name[index->size + 1] = '\0';
1593 +
1594 + if(strcmp(index->name, str) > 0)
1595 + break;
1596 +
1597 + length = index->index;
1598 + *next_block = index->start_block + sBlk->directory_table_start;
1599 + }
1600 +
1601 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1602 + return length;
1603 +}
1604 +
1605 +
1606 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1607 +{
1608 + struct inode *i = file->f_dentry->d_inode;
1609 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1610 + squashfs_super_block *sBlk = &msBlk->sBlk;
1611 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1612 + SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
1613 + squashfs_dir_header dirh;
1614 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1615 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1616 +
1617 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1618 +
1619 + lock_kernel();
1620 +
1621 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset, SQUASHFS_I(i)->u.s2.directory_index_start,
1622 + SQUASHFS_I(i)->u.s2.directory_index_offset, SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1623 +
1624 + while(length < i->i_size) {
1625 + /* read directory header */
1626 + if(msBlk->swap) {
1627 + squashfs_dir_header sdirh;
1628 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1629 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1630 + goto failed_read;
1631 + length += sizeof(sdirh);
1632 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1633 + } else {
1634 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1635 + next_offset, sizeof(dirh), &next_block, &next_offset))
1636 + goto failed_read;
1637 + length += sizeof(dirh);
1638 + }
1639 +
1640 + dir_count = dirh.count + 1;
1641 + while(dir_count--) {
1642 + if(msBlk->swap) {
1643 + squashfs_dir_entry sdire;
1644 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1645 + next_offset, sizeof(sdire), &next_block, &next_offset))
1646 + goto failed_read;
1647 + length += sizeof(sdire);
1648 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1649 + } else {
1650 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1651 + next_offset, sizeof(*dire), &next_block, &next_offset))
1652 + goto failed_read;
1653 + length += sizeof(*dire);
1654 + }
1655 +
1656 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1657 + next_offset, dire->size + 1, &next_block, &next_offset))
1658 + goto failed_read;
1659 + length += dire->size + 1;
1660 +
1661 + if(file->f_pos >= length)
1662 + continue;
1663 +
1664 + dire->name[dire->size + 1] = '\0';
1665 +
1666 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", (unsigned int) dirent,
1667 + dire->name, dire->size + 1, (int) file->f_pos,
1668 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1669 +
1670 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1671 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1672 + TRACE("Filldir returned less than 0\n");
1673 + unlock_kernel();
1674 + return dirs_read;
1675 + }
1676 +
1677 + file->f_pos = length;
1678 + dirs_read ++;
1679 + }
1680 + }
1681 +
1682 + unlock_kernel();
1683 + return dirs_read;
1684 +
1685 +failed_read:
1686 + unlock_kernel();
1687 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1688 + return 0;
1689 +}
1690 +
1691 +
1692 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
1693 +{
1694 + const unsigned char *name =dentry->d_name.name;
1695 + int len = dentry->d_name.len;
1696 + struct inode *inode = NULL;
1697 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1698 + squashfs_super_block *sBlk = &msBlk->sBlk;
1699 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1700 + SQUASHFS_I(i)->offset, length = 0, dir_count;
1701 + squashfs_dir_header dirh;
1702 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1703 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1704 + int squashfs_2_1 = sBlk->s_major == 2 && sBlk->s_minor == 1;
1705 +
1706 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1707 +
1708 + lock_kernel();
1709 +
1710 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset, SQUASHFS_I(i)->u.s2.directory_index_start,
1711 + SQUASHFS_I(i)->u.s2.directory_index_offset, SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
1712 +
1713 + while(length < i->i_size) {
1714 + /* read directory header */
1715 + if(msBlk->swap) {
1716 + squashfs_dir_header sdirh;
1717 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1718 + sizeof(sdirh), &next_block, &next_offset))
1719 + goto failed_read;
1720 + length += sizeof(sdirh);
1721 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1722 + } else {
1723 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1724 + sizeof(dirh), &next_block, &next_offset))
1725 + goto failed_read;
1726 + length += sizeof(dirh);
1727 + }
1728 +
1729 + dir_count = dirh.count + 1;
1730 + while(dir_count--) {
1731 + if(msBlk->swap) {
1732 + squashfs_dir_entry sdire;
1733 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1734 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1735 + goto failed_read;
1736 + length += sizeof(sdire);
1737 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1738 + } else {
1739 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1740 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1741 + goto failed_read;
1742 + length += sizeof(*dire);
1743 + }
1744 +
1745 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1746 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1747 + goto failed_read;
1748 + length += dire->size + 1;
1749 +
1750 + if(squashfs_2_1 && name[0] < dire->name[0])
1751 + goto exit_loop;
1752 +
1753 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1754 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1755 +
1756 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1757 + name, dirh.start_block, dire->offset);
1758 +
1759 + inode = (msBlk->iget)(i->i_sb, ino);
1760 +
1761 + goto exit_loop;
1762 + }
1763 + }
1764 + }
1765 +
1766 +exit_loop:
1767 + d_add(dentry, inode);
1768 + unlock_kernel();
1769 + return ERR_PTR(0);
1770 +
1771 +failed_read:
1772 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1773 + goto exit_loop;
1774 +}
1775 +
1776 +
1777 +static void squashfs_put_super(struct super_block *s)
1778 +{
1779 + int i;
1780 +
1781 + if(s->s_fs_info) {
1782 + squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1783 + if(sbi->block_cache) {
1784 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1785 + if(sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)
1786 + kfree(sbi->block_cache[i].data);
1787 + kfree(sbi->block_cache);
1788 + }
1789 + if(sbi->read_data) kfree(sbi->read_data);
1790 + if(sbi->read_page) kfree(sbi->read_page);
1791 + if(sbi->uid) kfree(sbi->uid);
1792 + if(sbi->fragment) {
1793 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
1794 + if(sbi->fragment[i].data != NULL)
1795 + SQUASHFS_FREE(sbi->fragment[i].data);
1796 + kfree(sbi->fragment);
1797 + }
1798 + if(sbi->fragment_index) kfree(sbi->fragment_index);
1799 + kfree(s->s_fs_info);
1800 + s->s_fs_info = NULL;
1801 + }
1802 +}
1803 +
1804 +
1805 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1806 +{
1807 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1808 +}
1809 +
1810 +
1811 +static int __init init_squashfs_fs(void)
1812 +{
1813 + int err = init_inodecache();
1814 + if(err)
1815 + return err;
1816 +
1817 + printk(KERN_INFO "Squashfs 2.2 (released 2005/07/03) (C) 2002-2005 Phillip Lougher\n");
1818 +
1819 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1820 + ERROR("Failed to allocate zlib workspace\n");
1821 + destroy_inodecache();
1822 + return -ENOMEM;
1823 + }
1824 +
1825 + if((err = register_filesystem(&squashfs_fs_type))) {
1826 + vfree(stream.workspace);
1827 + destroy_inodecache();
1828 + }
1829 +
1830 + return err;
1831 +}
1832 +
1833 +
1834 +static void __exit exit_squashfs_fs(void)
1835 +{
1836 + vfree(stream.workspace);
1837 + unregister_filesystem(&squashfs_fs_type);
1838 + destroy_inodecache();
1839 +}
1840 +
1841 +
1842 +static kmem_cache_t * squashfs_inode_cachep;
1843 +
1844 +
1845 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1846 +{
1847 + struct squashfs_inode_info *ei;
1848 + ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1849 + if (!ei)
1850 + return NULL;
1851 + return &ei->vfs_inode;
1852 +}
1853 +
1854 +
1855 +static void squashfs_destroy_inode(struct inode *inode)
1856 +{
1857 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1858 +}
1859 +
1860 +
1861 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1862 +{
1863 + struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1864 +
1865 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1866 + SLAB_CTOR_CONSTRUCTOR)
1867 + inode_init_once(&ei->vfs_inode);
1868 +}
1869 +
1870 +
1871 +static int init_inodecache(void)
1872 +{
1873 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1874 + sizeof(struct squashfs_inode_info),
1875 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1876 + init_once, NULL);
1877 + if (squashfs_inode_cachep == NULL)
1878 + return -ENOMEM;
1879 + return 0;
1880 +}
1881 +
1882 +
1883 +static void destroy_inodecache(void)
1884 +{
1885 + if (kmem_cache_destroy(squashfs_inode_cachep))
1886 + printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1887 +}
1888 +
1889 +
1890 +module_init(init_squashfs_fs);
1891 +module_exit(exit_squashfs_fs);
1892 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1893 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1894 +MODULE_LICENSE("GPL");
1895 Index: linux-git/fs/squashfs/Makefile
1896 ===================================================================
1897 --- /dev/null
1898 +++ linux-git/fs/squashfs/Makefile
1899 @@ -0,0 +1,7 @@
1900 +#
1901 +# Makefile for the linux squashfs routines.
1902 +#
1903 +
1904 +obj-$(CONFIG_SQUASHFS) += squashfs.o
1905 +
1906 +squashfs-objs := inode.o
1907 Index: linux-git/include/linux/squashfs_fs.h
1908 ===================================================================
1909 --- /dev/null
1910 +++ linux-git/include/linux/squashfs_fs.h
1911 @@ -0,0 +1,519 @@
1912 +#ifndef SQUASHFS_FS
1913 +#define SQUASHFS_FS
1914 +/*
1915 + * Squashfs
1916 + *
1917 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
1918 + *
1919 + * This program is free software; you can redistribute it and/or
1920 + * modify it under the terms of the GNU General Public License
1921 + * as published by the Free Software Foundation; either version 2,
1922 + * or (at your option) any later version.
1923 + *
1924 + * This program is distributed in the hope that it will be useful,
1925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1927 + * GNU General Public License for more details.
1928 + *
1929 + * You should have received a copy of the GNU General Public License
1930 + * along with this program; if not, write to the Free Software
1931 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1932 + *
1933 + * squashfs_fs.h
1934 + */
1935 +
1936 +#ifdef CONFIG_SQUASHFS_VMALLOC
1937 +#define SQUASHFS_ALLOC(a) vmalloc(a)
1938 +#define SQUASHFS_FREE(a) vfree(a)
1939 +#else
1940 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
1941 +#define SQUASHFS_FREE(a) kfree(a)
1942 +#endif
1943 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
1944 +#define SQUASHFS_MAJOR 2
1945 +#define SQUASHFS_MINOR 1
1946 +#define SQUASHFS_MAGIC 0x73717368
1947 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1948 +#define SQUASHFS_START 0
1949 +
1950 +/* size of metadata (inode and directory) blocks */
1951 +#define SQUASHFS_METADATA_SIZE 8192
1952 +#define SQUASHFS_METADATA_LOG 13
1953 +
1954 +/* default size of data blocks */
1955 +#define SQUASHFS_FILE_SIZE 65536
1956 +#define SQUASHFS_FILE_LOG 16
1957 +
1958 +#define SQUASHFS_FILE_MAX_SIZE 65536
1959 +
1960 +/* Max number of uids and gids */
1961 +#define SQUASHFS_UIDS 256
1962 +#define SQUASHFS_GUIDS 255
1963 +
1964 +/* Max length of filename (not 255) */
1965 +#define SQUASHFS_NAME_LEN 256
1966 +
1967 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1968 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1969 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1970 +
1971 +/* Filesystem flags */
1972 +#define SQUASHFS_NOI 0
1973 +#define SQUASHFS_NOD 1
1974 +#define SQUASHFS_CHECK 2
1975 +#define SQUASHFS_NOF 3
1976 +#define SQUASHFS_NO_FRAG 4
1977 +#define SQUASHFS_ALWAYS_FRAG 5
1978 +#define SQUASHFS_DUPLICATE 6
1979 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
1980 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
1981 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
1982 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1983 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1984 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1985 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1986 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1987 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking) (noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))
1988 +
1989 +/* Max number of types and file types */
1990 +#define SQUASHFS_DIR_TYPE 1
1991 +#define SQUASHFS_FILE_TYPE 2
1992 +#define SQUASHFS_SYMLINK_TYPE 3
1993 +#define SQUASHFS_BLKDEV_TYPE 4
1994 +#define SQUASHFS_CHRDEV_TYPE 5
1995 +#define SQUASHFS_FIFO_TYPE 6
1996 +#define SQUASHFS_SOCKET_TYPE 7
1997 +#define SQUASHFS_LDIR_TYPE 8
1998 +
1999 +/* 1.0 filesystem type definitions */
2000 +#define SQUASHFS_TYPES 5
2001 +#define SQUASHFS_IPC_TYPE 0
2002 +
2003 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
2004 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
2005 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
2006 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
2007 +
2008 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
2009 +
2010 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
2011 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
2012 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
2013 +
2014 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
2015 +
2016 +/*
2017 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
2018 + * offset within that block
2019 + */
2020 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
2021 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
2022 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
2023 + + (B)))
2024 +
2025 +/* Compute 32 bit VFS inode number from squashfs inode number */
2026 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
2027 +
2028 +/* Translate between VFS mode and squashfs mode */
2029 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
2030 +
2031 +/* fragment and fragment table defines */
2032 +typedef unsigned int squashfs_fragment_index;
2033 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
2034 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
2035 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
2036 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
2037 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
2038 +
2039 +/* cached data constants for filesystem */
2040 +#define SQUASHFS_CACHED_BLKS 8
2041 +
2042 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
2043 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
2044 +
2045 +#define SQUASHFS_MARKER_BYTE 0xff
2046 +
2047 +
2048 +/*
2049 + * definitions for structures on disk
2050 + */
2051 +
2052 +typedef unsigned int squashfs_block;
2053 +typedef long long squashfs_inode;
2054 +
2055 +typedef unsigned int squashfs_uid;
2056 +
2057 +typedef struct squashfs_super_block {
2058 + unsigned int s_magic;
2059 + unsigned int inodes;
2060 + unsigned int bytes_used;
2061 + unsigned int uid_start;
2062 + unsigned int guid_start;
2063 + unsigned int inode_table_start;
2064 + unsigned int directory_table_start;
2065 + unsigned int s_major:16;
2066 + unsigned int s_minor:16;
2067 + unsigned int block_size_1:16;
2068 + unsigned int block_log:16;
2069 + unsigned int flags:8;
2070 + unsigned int no_uids:8;
2071 + unsigned int no_guids:8;
2072 + unsigned int mkfs_time /* time of filesystem creation */;
2073 + squashfs_inode root_inode;
2074 + unsigned int block_size;
2075 + unsigned int fragments;
2076 + unsigned int fragment_table_start;
2077 +} __attribute__ ((packed)) squashfs_super_block;
2078 +
2079 +typedef struct {
2080 + unsigned int index:27;
2081 + unsigned int start_block:29;
2082 + unsigned char size;
2083 + unsigned char name[0];
2084 +} __attribute__ ((packed)) squashfs_dir_index;
2085 +
2086 +typedef struct {
2087 + unsigned int inode_type:4;
2088 + unsigned int mode:12; /* protection */
2089 + unsigned int uid:8; /* index into uid table */
2090 + unsigned int guid:8; /* index into guid table */
2091 +} __attribute__ ((packed)) squashfs_base_inode_header;
2092 +
2093 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
2094 +
2095 +typedef struct {
2096 + unsigned int inode_type:4;
2097 + unsigned int mode:12; /* protection */
2098 + unsigned int uid:8; /* index into uid table */
2099 + unsigned int guid:8; /* index into guid table */
2100 + unsigned short rdev;
2101 +} __attribute__ ((packed)) squashfs_dev_inode_header;
2102 +
2103 +typedef struct {
2104 + unsigned int inode_type:4;
2105 + unsigned int mode:12; /* protection */
2106 + unsigned int uid:8; /* index into uid table */
2107 + unsigned int guid:8; /* index into guid table */
2108 + unsigned short symlink_size;
2109 + char symlink[0];
2110 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
2111 +
2112 +typedef struct {
2113 + unsigned int inode_type:4;
2114 + unsigned int mode:12; /* protection */
2115 + unsigned int uid:8; /* index into uid table */
2116 + unsigned int guid:8; /* index into guid table */
2117 + unsigned int mtime;
2118 + squashfs_block start_block;
2119 + unsigned int fragment;
2120 + unsigned int offset;
2121 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2122 + unsigned short block_list[0];
2123 +} __attribute__ ((packed)) squashfs_reg_inode_header;
2124 +
2125 +typedef struct {
2126 + unsigned int inode_type:4;
2127 + unsigned int mode:12; /* protection */
2128 + unsigned int uid:8; /* index into uid table */
2129 + unsigned int guid:8; /* index into guid table */
2130 + unsigned int file_size:19;
2131 + unsigned int offset:13;
2132 + unsigned int mtime;
2133 + unsigned int start_block:24;
2134 +} __attribute__ ((packed)) squashfs_dir_inode_header;
2135 +
2136 +typedef struct {
2137 + unsigned int inode_type:4;
2138 + unsigned int mode:12; /* protection */
2139 + unsigned int uid:8; /* index into uid table */
2140 + unsigned int guid:8; /* index into guid table */
2141 + unsigned int file_size:27;
2142 + unsigned int offset:13;
2143 + unsigned int mtime;
2144 + unsigned int start_block:24;
2145 + unsigned int i_count:16;
2146 + squashfs_dir_index index[0];
2147 +} __attribute__ ((packed)) squashfs_ldir_inode_header;
2148 +
2149 +typedef union {
2150 + squashfs_base_inode_header base;
2151 + squashfs_dev_inode_header dev;
2152 + squashfs_symlink_inode_header symlink;
2153 + squashfs_reg_inode_header reg;
2154 + squashfs_dir_inode_header dir;
2155 + squashfs_ldir_inode_header ldir;
2156 + squashfs_ipc_inode_header ipc;
2157 +} squashfs_inode_header;
2158 +
2159 +typedef struct {
2160 + unsigned int offset:13;
2161 + unsigned int type:3;
2162 + unsigned int size:8;
2163 + char name[0];
2164 +} __attribute__ ((packed)) squashfs_dir_entry;
2165 +
2166 +typedef struct {
2167 + unsigned int count:8;
2168 + unsigned int start_block:24;
2169 +} __attribute__ ((packed)) squashfs_dir_header;
2170 +
2171 +typedef struct {
2172 + unsigned int start_block;
2173 + unsigned int size;
2174 +} __attribute__ ((packed)) squashfs_fragment_entry;
2175 +
2176 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
2177 +extern int squashfs_uncompress_init(void);
2178 +extern int squashfs_uncompress_exit(void);
2179 +
2180 +/*
2181 + * macros to convert each packed bitfield structure from little endian to big
2182 + * endian and vice versa. These are needed when creating or using a filesystem on a
2183 + * machine with different byte ordering to the target architecture.
2184 + *
2185 + */
2186 +
2187 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
2188 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
2189 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
2190 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
2191 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
2192 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
2193 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
2194 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
2195 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
2196 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
2197 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
2198 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
2199 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
2200 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
2201 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
2202 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
2203 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
2204 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
2205 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
2206 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
2207 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
2208 +}
2209 +
2210 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
2211 + SQUASHFS_MEMSET(s, d, n);\
2212 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2213 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2214 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
2215 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
2216 +}
2217 +
2218 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
2219 +
2220 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
2221 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
2222 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
2223 +}
2224 +
2225 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
2226 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
2227 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
2228 +}
2229 +
2230 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
2231 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
2232 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
2233 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
2234 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
2235 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
2236 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
2237 +}
2238 +
2239 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
2240 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
2241 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
2242 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
2243 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2244 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2245 +}
2246 +
2247 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
2248 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ldir_inode_header));\
2249 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
2250 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
2251 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
2252 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
2253 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
2254 +}
2255 +
2256 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
2257 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_index));\
2258 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
2259 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
2260 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
2261 +}
2262 +
2263 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2264 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2265 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
2266 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2267 +}
2268 +
2269 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2270 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2271 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2272 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
2273 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
2274 +}
2275 +
2276 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2277 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2278 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2279 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
2280 +}
2281 +
2282 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2283 + int entry;\
2284 + int bit_position;\
2285 + SQUASHFS_MEMSET(s, d, n * 2);\
2286 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2287 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2288 +}
2289 +
2290 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2291 + int entry;\
2292 + int bit_position;\
2293 + SQUASHFS_MEMSET(s, d, n * 4);\
2294 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2295 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2296 +}
2297 +
2298 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2299 + int entry;\
2300 + int bit_position;\
2301 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
2302 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2303 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2304 +}
2305 +
2306 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2307 +
2308 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2309 +typedef struct {
2310 + unsigned int inode_type:4;
2311 + unsigned int mode:12; /* protection */
2312 + unsigned int uid:4; /* index into uid table */
2313 + unsigned int guid:4; /* index into guid table */
2314 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2315 +
2316 +typedef struct {
2317 + unsigned int inode_type:4;
2318 + unsigned int mode:12; /* protection */
2319 + unsigned int uid:4; /* index into uid table */
2320 + unsigned int guid:4; /* index into guid table */
2321 + unsigned int type:4;
2322 + unsigned int offset:4;
2323 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2324 +
2325 +typedef struct {
2326 + unsigned int inode_type:4;
2327 + unsigned int mode:12; /* protection */
2328 + unsigned int uid:4; /* index into uid table */
2329 + unsigned int guid:4; /* index into guid table */
2330 + unsigned short rdev;
2331 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2332 +
2333 +typedef struct {
2334 + unsigned int inode_type:4;
2335 + unsigned int mode:12; /* protection */
2336 + unsigned int uid:4; /* index into uid table */
2337 + unsigned int guid:4; /* index into guid table */
2338 + unsigned short symlink_size;
2339 + char symlink[0];
2340 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2341 +
2342 +typedef struct {
2343 + unsigned int inode_type:4;
2344 + unsigned int mode:12; /* protection */
2345 + unsigned int uid:4; /* index into uid table */
2346 + unsigned int guid:4; /* index into guid table */
2347 + unsigned int mtime;
2348 + squashfs_block start_block;
2349 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2350 + unsigned short block_list[0];
2351 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2352 +
2353 +typedef struct {
2354 + unsigned int inode_type:4;
2355 + unsigned int mode:12; /* protection */
2356 + unsigned int uid:4; /* index into uid table */
2357 + unsigned int guid:4; /* index into guid table */
2358 + unsigned int file_size:19;
2359 + unsigned int offset:13;
2360 + unsigned int mtime;
2361 + unsigned int start_block:24;
2362 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
2363 +
2364 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2365 + SQUASHFS_MEMSET(s, d, n);\
2366 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2367 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2368 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2369 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2370 +}
2371 +
2372 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2373 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2374 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
2375 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2376 +}
2377 +
2378 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2379 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2380 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2381 +}
2382 +
2383 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2384 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2385 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2386 +}
2387 +
2388 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2389 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2390 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2391 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2392 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2393 +}
2394 +
2395 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2396 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2397 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2398 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2399 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2400 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2401 +}
2402 +#endif
2403 +
2404 +#ifdef __KERNEL__
2405 +/*
2406 + * macros used to swap each structure entry, taking into account
2407 + * bitfields and different bitfield placing conventions on differing architectures
2408 + */
2409 +#include <asm/byteorder.h>
2410 +#ifdef __BIG_ENDIAN
2411 + /* convert from little endian to big endian */
2412 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2413 +#else
2414 + /* convert from big endian to little endian */
2415 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2416 +#endif
2417 +
2418 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2419 + int bits;\
2420 + int b_pos = pos % 8;\
2421 + unsigned long long val = 0;\
2422 + unsigned char *s = (unsigned char *)p + (pos / 8);\
2423 + unsigned char *d = ((unsigned char *) &val) + 7;\
2424 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2425 + *d-- = *s++;\
2426 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2427 +}
2428 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
2429 +#endif
2430 +#endif
2431 Index: linux-git/include/linux/squashfs_fs_i.h
2432 ===================================================================
2433 --- /dev/null
2434 +++ linux-git/include/linux/squashfs_fs_i.h
2435 @@ -0,0 +1,43 @@
2436 +#ifndef SQUASHFS_FS_I
2437 +#define SQUASHFS_FS_I
2438 +/*
2439 + * Squashfs
2440 + *
2441 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
2442 + *
2443 + * This program is free software; you can redistribute it and/or
2444 + * modify it under the terms of the GNU General Public License
2445 + * as published by the Free Software Foundation; either version 2,
2446 + * or (at your option) any later version.
2447 + *
2448 + * This program is distributed in the hope that it will be useful,
2449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2451 + * GNU General Public License for more details.
2452 + *
2453 + * You should have received a copy of the GNU General Public License
2454 + * along with this program; if not, write to the Free Software
2455 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2456 + *
2457 + * squashfs_fs_i.h
2458 + */
2459 +
2460 +typedef struct squashfs_inode_info {
2461 + unsigned int start_block;
2462 + unsigned int block_list_start;
2463 + unsigned int offset;
2464 + union {
2465 + struct {
2466 + unsigned int fragment_start_block;
2467 + unsigned int fragment_size;
2468 + unsigned int fragment_offset;
2469 + } s1;
2470 + struct {
2471 + unsigned int directory_index_start;
2472 + unsigned int directory_index_offset;
2473 + unsigned int directory_index_count;
2474 + } s2;
2475 + } u;
2476 + struct inode vfs_inode;
2477 + } squashfs_inode_info;
2478 +#endif
2479 Index: linux-git/include/linux/squashfs_fs_sb.h
2480 ===================================================================
2481 --- /dev/null
2482 +++ linux-git/include/linux/squashfs_fs_sb.h
2483 @@ -0,0 +1,65 @@
2484 +#ifndef SQUASHFS_FS_SB
2485 +#define SQUASHFS_FS_SB
2486 +/*
2487 + * Squashfs
2488 + *
2489 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
2490 + *
2491 + * This program is free software; you can redistribute it and/or
2492 + * modify it under the terms of the GNU General Public License
2493 + * as published by the Free Software Foundation; either version 2,
2494 + * or (at your option) any later version.
2495 + *
2496 + * This program is distributed in the hope that it will be useful,
2497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2499 + * GNU General Public License for more details.
2500 + *
2501 + * You should have received a copy of the GNU General Public License
2502 + * along with this program; if not, write to the Free Software
2503 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2504 + *
2505 + * squashfs_fs_sb.h
2506 + */
2507 +
2508 +#include <linux/squashfs_fs.h>
2509 +
2510 +typedef struct {
2511 + unsigned int block;
2512 + int length;
2513 + unsigned int next_index;
2514 + char *data;
2515 + } squashfs_cache;
2516 +
2517 +struct squashfs_fragment_cache {
2518 + unsigned int block;
2519 + int length;
2520 + unsigned int locked;
2521 + char *data;
2522 + };
2523 +
2524 +typedef struct squashfs_sb_info {
2525 + squashfs_super_block sBlk;
2526 + int devblksize;
2527 + int devblksize_log2;
2528 + int swap;
2529 + squashfs_cache *block_cache;
2530 + struct squashfs_fragment_cache *fragment;
2531 + int next_cache;
2532 + int next_fragment;
2533 + squashfs_uid *uid;
2534 + squashfs_uid *guid;
2535 + squashfs_fragment_index *fragment_index;
2536 + unsigned int read_size;
2537 + char *read_data;
2538 + char *read_page;
2539 + struct semaphore read_page_mutex;
2540 + struct semaphore block_cache_mutex;
2541 + struct semaphore fragment_mutex;
2542 + wait_queue_head_t waitq;
2543 + wait_queue_head_t fragment_wait_queue;
2544 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
2545 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2546 + char *block_list, unsigned short **block_p, unsigned int *bsize);
2547 + } squashfs_sb_info;
2548 +#endif
2549 Index: linux-git/init/do_mounts_rd.c
2550 ===================================================================
2551 --- linux-git.orig/init/do_mounts_rd.c
2552 +++ linux-git/init/do_mounts_rd.c
2553 @@ -5,6 +5,7 @@
2554 #include <linux/ext2_fs.h>
2555 #include <linux/romfs_fs.h>
2556 #include <linux/cramfs_fs.h>
2557 +#include <linux/squashfs_fs.h>
2558 #include <linux/initrd.h>
2559 #include <linux/string.h>
2560
2561 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
2562 * numbers could not be found.
2563 *
2564 * We currently check for the following magic numbers:
2565 + * squashfs
2566 * minix
2567 * ext2
2568 * romfs
2569 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
2570 struct ext2_super_block *ext2sb;
2571 struct romfs_super_block *romfsb;
2572 struct cramfs_super *cramfsb;
2573 + struct squashfs_super_block *squashfsb;
2574 int nblocks = -1;
2575 unsigned char *buf;
2576
2577 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
2578 ext2sb = (struct ext2_super_block *) buf;
2579 romfsb = (struct romfs_super_block *) buf;
2580 cramfsb = (struct cramfs_super *) buf;
2581 + squashfsb = (struct squashfs_super_block *) buf;
2582 memset(buf, 0xe5, size);
2583
2584 /*
2585 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
2586 goto done;
2587 }
2588
2589 + /* squashfs is at block zero too */
2590 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2591 + printk(KERN_NOTICE
2592 + "RAMDISK: squashfs filesystem found at block %d\n",
2593 + start_block);
2594 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2595 + goto done;
2596 + }
2597 +
2598 /*
2599 * Read block 1 to test for minix and ext2 superblock
2600 */

  ViewVC Help
Powered by ViewVC 1.1.20