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