/[linux-patches]/genpatches-2.6/trunk/2.6.12-pre/4705_squashfs-2.1.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.12-pre/4705_squashfs-2.1.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20