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