]> git.pld-linux.org Git - packages/kernel.git/blob - squashfs1.3-2.4.21-patch
- obsolete
[packages/kernel.git] / squashfs1.3-2.4.21-patch
1 diff --new-file -ur linux-2.4.21/fs/Config.in linux-2.4.21-squashfs1.3/fs/Config.in
2 --- linux-2.4.21/fs/Config.in   Thu Nov 28 23:53:15 2002
3 +++ linux-2.4.21-squashfs1.3/fs/Config.in       Tue Jul 29 03:15:06 2003
4 @@ -47,6 +47,7 @@
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  bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
10  define_bool CONFIG_RAMFS y
11  
12 diff --new-file -ur linux-2.4.21/fs/Makefile linux-2.4.21-squashfs1.3/fs/Makefile
13 --- linux-2.4.21/fs/Makefile    Thu Nov 28 23:53:15 2002
14 +++ linux-2.4.21-squashfs1.3/fs/Makefile        Tue Jul 29 03:15:06 2003
15 @@ -69,6 +69,7 @@
16  subdir-$(CONFIG_BEFS_FS)       += befs
17  subdir-$(CONFIG_JFS_FS)                += jfs
18  subdir-$(CONFIG_XFS_FS)                += xfs
19 +subdir-$(CONFIG_SQUASHFS)      += squashfs
20  
21  obj-$(CONFIG_BINFMT_AOUT)      += binfmt_aout.o
22  obj-$(CONFIG_BINFMT_EM86)      += binfmt_em86.o
23 diff --new-file -ur linux-2.4.21/fs/squashfs/Makefile linux-2.4.21-squashfs1.3/fs/squashfs/Makefile
24 --- linux-2.4.21/fs/squashfs/Makefile   Thu Jan  1 01:00:00 1970
25 +++ linux-2.4.21-squashfs1.3/fs/squashfs/Makefile       Tue Jul 29 03:15:06 2003
26 @@ -0,0 +1,11 @@
27 +#
28 +# Makefile for the linux squashfs routines.
29 +#
30 +
31 +O_TARGET := squashfs.o
32 +
33 +obj-y  := inode.o
34 +
35 +obj-m := $(O_TARGET)
36 +
37 +include $(TOPDIR)/Rules.make
38 diff --new-file -ur linux-2.4.21/fs/squashfs/inode.c linux-2.4.21-squashfs1.3/fs/squashfs/inode.c
39 --- linux-2.4.21/fs/squashfs/inode.c    Thu Jan  1 01:00:00 1970
40 +++ linux-2.4.21-squashfs1.3/fs/squashfs/inode.c        Tue Jul 29 03:15:06 2003
41 @@ -0,0 +1,970 @@
42 +/*
43 + * Squashfs - a compressed read only filesystem for Linux
44 + *
45 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
46 + *
47 + * This program is free software; you can redistribute it and/or
48 + * modify it under the terms of the GNU General Public License
49 + * as published by the Free Software Foundation; either version
50 + * 2 of the License, or (at your option) any later version.
51 + *
52 + * inode.c
53 + */
54 +
55 +#include <linux/types.h>
56 +#include <linux/squashfs_fs.h>
57 +#include <linux/module.h>
58 +#include <linux/errno.h>
59 +#include <linux/slab.h>
60 +#include <linux/fs.h>
61 +#include <linux/locks.h>
62 +#include <linux/init.h>
63 +#include <linux/dcache.h>
64 +#include <asm/uaccess.h>
65 +#include <linux/wait.h>
66 +#include <asm/semaphore.h>
67 +
68 +#include <linux/zlib.h>
69 +#include <linux/blkdev.h>
70 +#include <linux/vmalloc.h>
71 +
72 +#ifdef SQUASHFS_TRACE
73 +#define TRACE(s, args...)                              printk(KERN_NOTICE "SQUASHFS: "s, ## args)
74 +#else
75 +#define TRACE(s, args...)                              {}
76 +#endif
77 +
78 +#define ERROR(s, args...)                              printk(KERN_ERR "SQUASHFS error: "s, ## args)
79 +
80 +#define SERROR(s, args...)                             if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
81 +#define WARNING(s, args...)                            printk(KERN_WARNING "SQUASHFS: "s, ## args)
82 +
83 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
84 +static void squashfs_put_super(struct super_block *);
85 +static int squashfs_statfs(struct super_block *, struct statfs *);
86 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
87 +static int squashfs_readpage(struct file *file, struct page *page);
88 +static int squashfs_readdir(struct file *, void *, filldir_t);
89 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
90 +static unsigned int read_data(struct super_block *s, char *buffer,
91 +               unsigned int index, int length, unsigned int *next_index);
92 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
93 +               unsigned int block, unsigned int offset, int length,
94 +               unsigned int *next_block, unsigned int *next_offset);
95 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
96 +static void squashfs_put_super(struct super_block *s);
97 +
98 +DECLARE_MUTEX(read_data_mutex);
99 +
100 +static z_stream stream;
101 +
102 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
103 +
104 +static unsigned char squashfs_filetype_table[] = {
105 +       DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
106 +};
107 +
108 +static struct super_operations squashfs_ops = {
109 +       statfs: squashfs_statfs,
110 +       put_super: squashfs_put_super,
111 +};
112 +
113 +static struct address_space_operations squashfs_symlink_aops = {
114 +       readpage: squashfs_symlink_readpage
115 +};
116 +
117 +static struct address_space_operations squashfs_aops = {
118 +       readpage: squashfs_readpage
119 +};
120 +
121 +static struct file_operations squashfs_dir_ops = {
122 +       read: generic_read_dir,
123 +       readdir: squashfs_readdir
124 +};
125 +
126 +static struct inode_operations squashfs_dir_inode_ops = {
127 +       lookup: squashfs_lookup
128 +};
129 +
130 +
131 +static unsigned int read_data(struct super_block *s, char *buffer,
132 +               unsigned int index, int length, unsigned int *next_index)
133 +{
134 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
135 +       struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
136 +       unsigned short c_byte;
137 +       unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
138 +       unsigned int cur_index = index >> msBlk->devblksize_log2;
139 +       int bytes, avail_bytes, b, k;
140 +       char *c_buffer;
141 +       unsigned int compressed;
142 +
143 +       if(!(bh[0] = sb_bread(s, cur_index)))
144 +               goto read_failure;
145 +
146 +       if(length)
147 +               c_byte = length;
148 +       else {
149 +               if(msBlk->devblksize - offset == 1) {
150 +                       if(msBlk->swap)
151 +                               ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
152 +                       else
153 +                               ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
154 +                       brelse(bh[0]);
155 +                       if(!(bh[0] = sb_bread(s, ++cur_index)))
156 +                               goto read_failure;
157 +                       if(msBlk->swap)
158 +                               ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data); 
159 +                       else
160 +                               ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data); 
161 +                       offset = 1;
162 +               }
163 +               else {
164 +                       if(msBlk->swap) {
165 +                               ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
166 +                               ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1)); 
167 +                       } else
168 +                               c_byte = *((unsigned short *) (bh[0]->b_data + offset));
169 +                       offset += 2;
170 +               }
171 +               if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
172 +                       if(offset == msBlk->devblksize) {
173 +                               brelse(bh[0]);
174 +                               if(!(bh[0] = sb_bread(s, ++cur_index)))
175 +                                       goto read_failure;
176 +                               offset = 0;
177 +                       }
178 +                       if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
179 +                               ERROR("Metadata block marker corrupt @ %x\n", index);
180 +                               brelse(bh[0]);
181 +                               return 0;
182 +                       }
183 +                       offset ++;
184 +               }
185 +       }
186 +
187 +       bytes = msBlk->devblksize - offset;
188 +       c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
189 +       c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
190 +
191 +       TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
192 +
193 +       for(b = 1; bytes < c_byte; b++) {
194 +               if(!(bh[b] = sb_bread(s, ++cur_index)))
195 +                       goto block_release;
196 +               bytes += msBlk->devblksize;
197 +       }
198 +
199 +       if(compressed)
200 +               down(&read_data_mutex);
201 +
202 +       for(bytes = 0, k = 0; k < b; k++) {
203 +               avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
204 +               memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
205 +               bytes += avail_bytes;
206 +               offset = 0;
207 +               brelse(bh[k]);
208 +       }
209 +
210 +       /*
211 +        * uncompress block
212 +        */
213 +       if(compressed) {
214 +               int zlib_err;
215 +
216 +               stream.next_in = c_buffer;
217 +               stream.avail_in = c_byte;
218 +               stream.next_out = buffer;
219 +               stream.avail_out = msBlk->read_size;
220 +               if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
221 +                               ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
222 +                               ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
223 +                       ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
224 +                       bytes = 0;
225 +               } else
226 +                       bytes = stream.total_out;
227 +               up(&read_data_mutex);
228 +       }
229 +
230 +       if(next_index)
231 +               *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
232 +
233 +       return bytes;
234 +
235 +block_release:
236 +       while(--b >= 0) brelse(bh[b]);
237 +
238 +read_failure:
239 +       ERROR("sb_bread failed reading block 0x%x\n", cur_index);
240 +       return 0;
241 +}
242 +
243 +
244 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
245 +               unsigned int block, unsigned int offset, int length,
246 +               unsigned int *next_block, unsigned int *next_offset)
247 +{
248 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
249 +       int n, i, bytes, return_length = length;
250 +       unsigned int next_index;
251 +
252 +       TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
253 +
254 +       for(;;) {
255 +               for(i = 0; i < SQUASHFS_CACHED_BLKS; i++) 
256 +                       if(msBlk->block_cache[i].block == block)
257 +                               break; 
258 +               
259 +               down(&msBlk->block_cache_mutex);
260 +               if(i == SQUASHFS_CACHED_BLKS) {
261 +                       /* read inode header block */
262 +                       for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
263 +                               if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
264 +                                       break;
265 +                       if(n == 0) {
266 +                               up(&msBlk->block_cache_mutex);
267 +                               sleep_on(&msBlk->waitq);
268 +                               continue;
269 +                       }
270 +                       msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
271 +
272 +                       if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
273 +                               if(!(msBlk->block_cache[i].data = (unsigned char *)
274 +                                                       kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
275 +                                       ERROR("Failed to allocate cache block\n");
276 +                                       up(&msBlk->block_cache_mutex);
277 +                                       return 0;
278 +                               }
279 +                       }
280 +       
281 +                       msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
282 +                       up(&msBlk->block_cache_mutex);
283 +                       if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
284 +                                                       &next_index))) {
285 +                               ERROR("Unable to read cache block [%x:%x]\n", block, offset);
286 +                               return 0;
287 +                       }
288 +                       down(&msBlk->block_cache_mutex);
289 +                       wake_up(&msBlk->waitq);
290 +                       msBlk->block_cache[i].block = block;
291 +                       msBlk->block_cache[i].next_index = next_index;
292 +                       TRACE("Read cache block [%x:%x]\n", block, offset);
293 +               }
294 +
295 +               if(msBlk->block_cache[i].block != block) {
296 +                       up(&msBlk->block_cache_mutex);
297 +                       continue;
298 +               }
299 +
300 +               if((bytes = msBlk->block_cache[i].length - offset) >= length) {
301 +                       if(buffer)
302 +                               memcpy(buffer, msBlk->block_cache[i].data + offset, length);
303 +                       if(msBlk->block_cache[i].length - offset == length) {
304 +                               *next_block = msBlk->block_cache[i].next_index;
305 +                               *next_offset = 0;
306 +                       } else {
307 +                               *next_block = block;
308 +                               *next_offset = offset + length;
309 +                       }
310 +       
311 +                       up(&msBlk->block_cache_mutex);
312 +                       return return_length;
313 +               } else {
314 +                       if(buffer) {
315 +                               memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
316 +                               buffer += bytes;
317 +                       }
318 +                       block = msBlk->block_cache[i].next_index;
319 +                       up(&msBlk->block_cache_mutex);
320 +                       length -= bytes;
321 +                       offset = 0;
322 +               }
323 +       }
324 +}
325 +
326 +
327 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
328 +{
329 +       struct inode *i = new_inode(s);
330 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
331 +       squashfs_super_block *sBlk = &msBlk->sBlk;
332 +       unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
333 +       unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
334 +       unsigned int next_block, next_offset;
335 +       squashfs_base_inode_header inodeb;
336 +
337 +       TRACE("Entered squashfs_iget\n");
338 +
339 +       if(msBlk->swap) {
340 +               squashfs_base_inode_header sinodeb;
341 +
342 +               if(!squashfs_get_cached_block(s, (char *) &sinodeb, block,  offset,
343 +                                       sizeof(sinodeb), &next_block, &next_offset))
344 +                       goto failed_read;
345 +               SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
346 +       } else
347 +               if(!squashfs_get_cached_block(s, (char *) &inodeb, block,  offset,
348 +                                       sizeof(inodeb), &next_block, &next_offset))
349 +                       goto failed_read;
350 +
351 +       i->i_nlink = 1;
352 +
353 +       i->i_mtime = sBlk->mkfs_time;
354 +       i->i_atime = sBlk->mkfs_time;
355 +       i->i_ctime = sBlk->mkfs_time;
356 +
357 +       if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
358 +               i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
359 +       i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
360 +
361 +       i->i_mode = inodeb.mode;
362 +
363 +       switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
364 +               case SQUASHFS_FILE_TYPE: {
365 +                       squashfs_reg_inode_header inodep;
366 +
367 +                       if(msBlk->swap) {
368 +                               squashfs_reg_inode_header sinodep;
369 +
370 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
371 +                                                       &next_block, &next_offset))
372 +                                       goto failed_read;
373 +                               SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
374 +                       } else
375 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
376 +                                                       &next_block, &next_offset))
377 +                                       goto failed_read;
378 +
379 +                       i->i_size = inodep.file_size;
380 +                       i->i_fop = &generic_ro_fops;
381 +                       i->i_data.a_ops = &squashfs_aops;
382 +                       i->i_mode |= S_IFREG;
383 +                       i->i_mtime = inodep.mtime;
384 +                       i->i_atime = inodep.mtime;
385 +                       i->i_ctime = inodep.mtime;
386 +                       i->u.squashfs_i.start_block = inodep.start_block;
387 +                       i->u.squashfs_i.block_list_start = next_block;
388 +                       i->u.squashfs_i.offset = next_offset;
389 +                       TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
390 +                                       SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
391 +                       break;
392 +               }
393 +               case SQUASHFS_DIR_TYPE: {
394 +                       squashfs_dir_inode_header inodep;
395 +
396 +                       if(msBlk->swap) {
397 +                               squashfs_dir_inode_header sinodep;
398 +
399 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
400 +                                                       &next_block, &next_offset))
401 +                                       goto failed_read;
402 +                               SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
403 +                       } else
404 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
405 +                                                       &next_block, &next_offset))
406 +                                       goto failed_read;
407 +
408 +                       i->i_size = inodep.file_size;
409 +                       i->i_op = &squashfs_dir_inode_ops;
410 +                       i->i_fop = &squashfs_dir_ops;
411 +                       i->i_mode |= S_IFDIR;
412 +                       i->i_mtime = inodep.mtime;
413 +                       i->i_atime = inodep.mtime;
414 +                       i->i_ctime = inodep.mtime;
415 +                       i->u.squashfs_i.start_block = inodep.start_block;
416 +                       i->u.squashfs_i.offset = inodep.offset;
417 +                       TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
418 +                                       inodep.start_block, inodep.offset);
419 +                       break;
420 +               }
421 +               case SQUASHFS_SYMLINK_TYPE: {
422 +                       squashfs_symlink_inode_header inodep;
423 +       
424 +                       if(msBlk->swap) {
425 +                               squashfs_symlink_inode_header sinodep;
426 +
427 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
428 +                                                       &next_block, &next_offset))
429 +                                       goto failed_read;
430 +                               SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
431 +                       } else
432 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
433 +                                                       &next_block, &next_offset))
434 +                                       goto failed_read;
435 +
436 +                       i->i_size = inodep.symlink_size;
437 +                       i->i_op = &page_symlink_inode_operations;
438 +                       i->i_data.a_ops = &squashfs_symlink_aops;
439 +                       i->i_mode |= S_IFLNK;
440 +                       i->u.squashfs_i.start_block = next_block;
441 +                       i->u.squashfs_i.offset = next_offset;
442 +                       TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
443 +                               SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
444 +                       break;
445 +                }
446 +                case SQUASHFS_BLKDEV_TYPE:
447 +                case SQUASHFS_CHRDEV_TYPE: {
448 +                       squashfs_dev_inode_header inodep;
449 +
450 +                       if(msBlk->swap) {
451 +                               squashfs_dev_inode_header sinodep;
452 +
453 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
454 +                                                       &next_block, &next_offset))
455 +                                       goto failed_read;
456 +                               SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
457 +                       } else  
458 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
459 +                                                       &next_block, &next_offset))
460 +                                       goto failed_read;
461 +
462 +                       i->i_size = 0;
463 +                       i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
464 +                       init_special_inode(i, i->i_mode, inodep.rdev);
465 +                       TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
466 +                       break;
467 +                }
468 +                case SQUASHFS_IPC_TYPE: {
469 +                       squashfs_ipc_inode_header inodep;
470 +
471 +                       if(msBlk->swap) {
472 +                               squashfs_ipc_inode_header sinodep;
473 +
474 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
475 +                                                       &next_block, &next_offset))
476 +                                       goto failed_read;
477 +                               SQUASHFS_SWAP_IPC_INODE_HEADER(&inodep, &sinodep);
478 +                       } else  
479 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
480 +                                                       &next_block, &next_offset))
481 +                                       goto failed_read;
482 +
483 +                       i->i_size = 0;
484 +                       i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
485 +                       i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
486 +                       init_special_inode(i, i->i_mode, 0);
487 +                       break;
488 +                }
489 +                default:
490 +                       ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
491 +                               goto failed_read1;
492 +       }
493 +       
494 +       if(inodeb.guid == SQUASHFS_GUIDS)
495 +               i->i_gid = i->i_uid;
496 +       else
497 +               i->i_gid = msBlk->guid[inodeb.guid];
498 +
499 +       return i;
500 +
501 +failed_read:
502 +       ERROR("Unable to read inode [%x:%x]\n", block, offset);
503 +
504 +failed_read1:
505 +       return NULL;
506 +}
507 +
508 +
509 +static struct super_block *squashfs_read_super(struct super_block *s,
510 +               void *data, int silent)
511 +{
512 +       kdev_t dev = s->s_dev;
513 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
514 +       squashfs_super_block *sBlk = &msBlk->sBlk;
515 +       int i;
516 +
517 +       TRACE("Entered squashfs_read_superblock\n");
518 +
519 +       msBlk->devblksize = get_hardsect_size(dev);
520 +       if(msBlk->devblksize < BLOCK_SIZE)
521 +               msBlk->devblksize = BLOCK_SIZE;
522 +       msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
523 +       set_blocksize(dev, msBlk->devblksize);
524 +       s->s_blocksize = msBlk->devblksize;
525 +       s->s_blocksize_bits = msBlk->devblksize_log2;
526 +
527 +       init_MUTEX(&msBlk->read_page_mutex);
528 +       init_MUTEX(&msBlk->block_cache_mutex);
529 +       
530 +       init_waitqueue_head(&msBlk->waitq);
531 +
532 +       if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
533 +               SERROR("unable to read superblock\n");
534 +               goto failed_mount;
535 +       }
536 +
537 +       /* Check it is a SQUASHFS superblock */
538 +       msBlk->swap = 0;
539 +       if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
540 +               if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
541 +                       squashfs_super_block sblk;
542 +                       WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
543 +                       SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
544 +                       memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
545 +                       msBlk->swap = 1;
546 +               } else  {
547 +                       SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
548 +                       goto failed_mount;
549 +               }
550 +       }
551 +
552 +       /* Check the MAJOR & MINOR versions */
553 +       if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
554 +               SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
555 +                               sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
556 +               goto failed_mount;
557 +       }
558 +
559 +       TRACE("Found valid superblock on %s\n", bdevname(dev));
560 +       TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
561 +       TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
562 +       TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
563 +       TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
564 +       TRACE("Block size %d\n", sBlk->block_size);
565 +       TRACE("Number of inodes %d\n", sBlk->inodes);
566 +       TRACE("Number of uids %d\n", sBlk->no_uids);
567 +       TRACE("Number of gids %d\n", sBlk->no_guids);
568 +       TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
569 +       TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
570 +       TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
571 +
572 +       s->s_flags |= MS_RDONLY;
573 +       s->s_op = &squashfs_ops;
574 +
575 +       /* Init inode_table block pointer array */
576 +       if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
577 +               ERROR("Failed to allocate block cache\n");
578 +               goto failed_mount;
579 +       }
580 +
581 +       for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
582 +               msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
583 +
584 +       msBlk->next_cache = 0;
585 +
586 +       /* Allocate read_data block */
587 +       msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
588 +       if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
589 +               ERROR("Failed to allocate read_data block\n");
590 +               goto failed_mount1;
591 +       }
592 +
593 +       /* Allocate read_page block */
594 +       if(sBlk->block_size > PAGE_CACHE_SIZE && 
595 +          !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
596 +               ERROR("Failed to allocate read_page block\n");
597 +               goto failed_mount2;
598 +       }
599 +
600 +       /* Allocate uid and gid tables */
601 +       if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
602 +               sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
603 +               ERROR("Failed to allocate uid/gid table\n");
604 +               goto failed_mount3;
605 +       }
606 +       msBlk->guid = msBlk->uid + sBlk->no_uids;
607 +   
608 +       if(msBlk->swap) {
609 +               squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
610 +
611 +               if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
612 +                               sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
613 +                       SERROR("unable to read uid/gid table\n");
614 +                       goto failed_mount4;
615 +               }
616 +               SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
617 +       } else
618 +               if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
619 +                               sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
620 +                       SERROR("unable to read uid/gid table\n");
621 +                       goto failed_mount4;
622 +               }
623 +
624 +       if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
625 +               ERROR("Root inode create failed\n");
626 +               goto failed_mount4;
627 +       }
628 +
629 +       TRACE("Leaving squashfs_read_super\n");
630 +       return s;
631 +
632 +failed_mount4:
633 +       kfree(msBlk->uid);
634 +failed_mount3:
635 +       kfree(msBlk->read_page);
636 +failed_mount2:
637 +       kfree(msBlk->read_data);
638 +failed_mount1:
639 +       kfree(msBlk->block_cache);
640 +failed_mount:
641 +       return NULL;
642 +}
643 +
644 +
645 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
646 +{
647 +       squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
648 +
649 +       TRACE("Entered squashfs_statfs\n");
650 +       buf->f_type = SQUASHFS_MAGIC;
651 +       buf->f_bsize = sBlk->block_size;
652 +       buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
653 +       buf->f_bfree = buf->f_bavail = 0;
654 +       buf->f_files = sBlk->inodes;
655 +       buf->f_ffree = 0;
656 +       buf->f_namelen = SQUASHFS_NAME_LEN;
657 +       return 0;
658 +}
659 +
660 +
661 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
662 +{
663 +       struct inode *inode = page->mapping->host;
664 +       int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
665 +       int block = inode->u.squashfs_i.start_block;
666 +       int offset = inode->u.squashfs_i.offset;
667 +
668 +       TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
669 +               page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
670 +
671 +       for(length = 0; length < index; length += bytes) {
672 +               if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
673 +                                       PAGE_CACHE_SIZE, &block, &offset))) {
674 +                       ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
675 +                       goto skip_read;
676 +               }
677 +       }
678 +
679 +       if(length != index) {
680 +               ERROR("(squashfs_symlink_readpage) length != index\n");
681 +               return 0;
682 +       }
683 +
684 +       bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
685 +       if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
686 +               ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
687 +
688 +skip_read:
689 +       memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
690 +       flush_dcache_page(page);
691 +       SetPageUptodate(page);
692 +       UnlockPage(page);
693 +
694 +       return 0;
695 +}
696 +
697 +
698 +#define SIZE 256
699 +static int squashfs_readpage(struct file *file, struct page *page)
700 +{
701 +       struct inode *inode = page->mapping->host;
702 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
703 +       squashfs_super_block *sBlk = &msBlk->sBlk;
704 +       unsigned char block_list[SIZE];
705 +       unsigned short *block_listp;
706 +       int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
707 +               page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
708 +               page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
709 +       int block = inode->u.squashfs_i.start_block, i = 0;
710 +       int bytes = 0, block_ptr = inode->u.squashfs_i.block_list_start;
711 +       int offset = inode->u.squashfs_i.offset;
712 +       int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
713 +       int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
714 +       
715 +       TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
716 +               inode->u.squashfs_i.start_block);
717 +
718 +       if(index > file_blocks)
719 +               goto skip_read;
720 +
721 +       for(;;) {
722 +               int blocks = (index + readahead_blks - i);
723 +               if(blocks > (SIZE >> 1)) {
724 +                       if((index - i) <= (SIZE >> 1))
725 +                               blocks = index - i;
726 +                       else
727 +                               blocks = SIZE >> 1;
728 +               }
729 +
730 +               if(msBlk->swap) {
731 +                       unsigned char sblock_list[SIZE];
732 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
733 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
734 +                               goto skip_read;
735 +                       }
736 +                       SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
737 +               } else
738 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
739 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
740 +                               goto skip_read;
741 +                       }
742 +               for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
743 +                       block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
744 +               if(blocks >= readahead_blks)
745 +                       break;
746 +       }
747 +
748 +       if(sBlk->block_log > PAGE_CACHE_SHIFT) {
749 +               int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
750 +               int start_index = page->index & ~mask;
751 +               int end_index = start_index | mask;
752 +               int byte_offset = 0;
753 +
754 +               down(&msBlk->read_page_mutex);
755 +               if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
756 +                       ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
757 +                       goto skip_read;
758 +               }
759 +
760 +               for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
761 +                       int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
762 +
763 +                       TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
764 +
765 +                       if(i == page->index)  {
766 +                               memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
767 +                               memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
768 +                               flush_dcache_page(page);
769 +                               SetPageUptodate(page);
770 +                               UnlockPage(page);
771 +                       }  else {
772 +                               struct page *push_page;
773 +
774 +                               if((push_page = grab_cache_page_nowait(page->mapping, i))) {
775 +                                       memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
776 +                                       memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
777 +                                       flush_dcache_page(push_page);
778 +                                       SetPageUptodate(push_page);
779 +                                       UnlockPage(push_page);
780 +                                       page_cache_release(push_page);
781 +                               }
782 +                       }
783 +               }
784 +               up( &msBlk->read_page_mutex);
785 +
786 +               return 0;
787 +
788 +       } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
789 +               if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
790 +                       ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
791 +
792 +       } else {
793 +               int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
794 +               char *p = (char *) page_address(page);
795 +               int byte;
796 +
797 +               if(i_end > file_blocks)
798 +                       i_end = file_blocks;
799 +
800 +               while(index < i_end) {
801 +                       if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
802 +                               ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
803 +                               goto skip_read;
804 +                       }
805 +                       block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
806 +                       p += byte;
807 +                       bytes += byte;
808 +                       index ++;
809 +                       block_listp ++;
810 +               }
811 +       }
812 +
813 +skip_read:
814 +       memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
815 +       flush_dcache_page(page);
816 +       SetPageUptodate(page);
817 +       UnlockPage(page);
818 +
819 +       return 0;
820 +}
821 +
822 +
823 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
824 +{
825 +       struct inode *i = file->f_dentry->d_inode;
826 +       squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
827 +       squashfs_super_block *sBlk = &msBlk->sBlk;
828 +       int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
829 +               i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
830 +       squashfs_dir_header dirh;
831 +       char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
832 +       squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
833 +
834 +       TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
835 +
836 +       while(length < i->i_size) {
837 +               /* read directory header */
838 +               if(msBlk->swap) {
839 +                       squashfs_dir_header sdirh;
840 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
841 +                                               next_offset, sizeof(sdirh), &next_block, &next_offset))
842 +                               goto failed_read;
843 +                       length += sizeof(sdirh);
844 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
845 +               } else {
846 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
847 +                                               next_offset, sizeof(dirh), &next_block, &next_offset))
848 +                               goto failed_read;
849 +                       length += sizeof(dirh);
850 +               }
851 +
852 +               dir_count = dirh.count + 1;
853 +               while(dir_count--) {
854 +                       if(msBlk->swap) {
855 +                               squashfs_dir_entry sdire;
856 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
857 +                                                       next_offset, sizeof(sdire), &next_block, &next_offset))
858 +                                       goto failed_read;
859 +                               length += sizeof(sdire);
860 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
861 +                       } else {
862 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
863 +                                                       next_offset, sizeof(*dire), &next_block, &next_offset))
864 +                                       goto failed_read;
865 +                               length += sizeof(*dire);
866 +                       }
867 +
868 +                       if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
869 +                                               next_offset, dire->size + 1, &next_block, &next_offset))
870 +                               goto failed_read;
871 +                       length += dire->size + 1;
872 +
873 +                       if(file->f_pos >= length)
874 +                               continue;
875 +
876 +                       dire->name[dire->size + 1] = '\0';
877 +
878 +                       TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
879 +                       dire->name, dire->size + 1, (int) file->f_pos,
880 +                       dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
881 +
882 +                       if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
883 +                                                       dire->offset), squashfs_filetype_table[dire->type]) < 0) {
884 +                               TRACE("Filldir returned less than 0\n");
885 +                               return dirs_read;
886 +                       }
887 +
888 +                       file->f_pos = length;
889 +                       dirs_read ++;
890 +               }
891 +       }
892 +
893 +       return dirs_read;
894 +
895 +failed_read:
896 +       ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
897 +       return 0;
898 +}
899 +
900 +
901 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
902 +{
903 +       const char *name =dentry->d_name.name;
904 +       int len = dentry->d_name.len;
905 +       struct inode *inode = NULL;
906 +       squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
907 +       squashfs_super_block *sBlk = &msBlk->sBlk;
908 +       int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
909 +               i->u.squashfs_i.offset, length = 0, dir_count;
910 +       squashfs_dir_header dirh;
911 +       char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
912 +       squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
913 +
914 +       TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
915 +
916 +       while(length < i->i_size) {
917 +               /* read directory header */
918 +               if(msBlk->swap) {
919 +                       squashfs_dir_header sdirh;
920 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
921 +                                               sizeof(sdirh), &next_block, &next_offset))
922 +                               goto failed_read;
923 +                       length += sizeof(sdirh);
924 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
925 +               } else {
926 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
927 +                                               sizeof(dirh), &next_block, &next_offset))
928 +                               goto failed_read;
929 +                       length += sizeof(dirh);
930 +               }
931 +
932 +               dir_count = dirh.count + 1;
933 +               while(dir_count--) {
934 +                       if(msBlk->swap) {
935 +                               squashfs_dir_entry sdire;
936 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
937 +                                                       next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
938 +                                       goto failed_read;
939 +                               length += sizeof(*dire);
940 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
941 +                       } else {
942 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
943 +                                                       next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
944 +                                       goto failed_read;
945 +                               length += sizeof(*dire);
946 +                       }
947 +
948 +                       if(!squashfs_get_cached_block(i->i_sb, dire->name,
949 +                                               next_block, next_offset, dire->size + 1, &next_block, &next_offset))
950 +                               goto failed_read;
951 +                       length += dire->size + 1;
952 +
953 +                       if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
954 +                               squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
955 +
956 +                               TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
957 +                                               name, dirh.start_block, dire->offset);
958 +
959 +                               inode = squashfs_iget(i->i_sb, ino);
960 +
961 +                               goto exit_loop;
962 +                       }
963 +               }
964 +       }
965 +
966 +exit_loop:
967 +       d_add(dentry, inode);
968 +       return ERR_PTR(0);
969 +
970 +failed_read:
971 +       ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
972 +       goto exit_loop;
973 +}
974 +
975 +
976 +static void squashfs_put_super(struct super_block *s)
977 +{
978 +       if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
979 +       if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
980 +       if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
981 +       if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
982 +       s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
983 +               s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
984 +}
985 +
986 +
987 +static int __init init_squashfs_fs(void)
988 +{
989 +
990 +       if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
991 +               ERROR("Failed to allocate zlib workspace\n");
992 +               return -ENOMEM;
993 +       }
994 +       return register_filesystem(&squashfs_fs_type);
995 +}
996 +
997 +
998 +static void __exit exit_squashfs_fs(void)
999 +{
1000 +       vfree(stream.workspace);
1001 +       unregister_filesystem(&squashfs_fs_type);
1002 +}
1003 +
1004 +
1005 +EXPORT_NO_SYMBOLS;
1006 +
1007 +module_init(init_squashfs_fs);
1008 +module_exit(exit_squashfs_fs);
1009 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1010 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1011 +MODULE_LICENSE("GPL");
1012 diff --new-file -ur linux-2.4.21/include/linux/fs.h linux-2.4.21-squashfs1.3/include/linux/fs.h
1013 --- linux-2.4.21/include/linux/fs.h     Fri Jun 13 15:51:38 2003
1014 +++ linux-2.4.21-squashfs1.3/include/linux/fs.h Tue Jul 29 03:15:06 2003
1015 @@ -327,6 +327,7 @@
1016  #include <linux/hppfs_fs_i.h>
1017  #include <linux/jffs2_fs_i.h>
1018  #include <linux/cramfs_fs_sb.h>
1019 +#include <linux/squashfs_fs_i.h>
1020  
1021  /*
1022   * Attribute flags.  These should be or-ed together to figure out what
1023 @@ -522,6 +523,7 @@
1024                 struct hostfs_inode_info        hostfs_i;
1025                 struct hppfs_inode_info         hppfs_i;
1026                 struct jffs2_inode_info         jffs2_i;
1027 +               struct squashfs_inode_info      squashfs_i;
1028                 void                            *generic_ip;
1029         } u;
1030  };
1031 @@ -735,6 +737,7 @@
1032  #include <linux/usbdev_fs_sb.h>
1033  #include <linux/cramfs_fs_sb.h>
1034  #include <linux/jffs2_fs_sb.h>
1035 +#include <linux/squashfs_fs_sb.h>
1036  
1037  extern struct list_head super_blocks;
1038  extern spinlock_t sb_lock;
1039 @@ -794,6 +797,7 @@
1040                 struct usbdev_sb_info   usbdevfs_sb;
1041                 struct jffs2_sb_info    jffs2_sb;
1042                 struct cramfs_sb_info   cramfs_sb;
1043 +               struct squashfs_sb_info squashfs_sb;
1044                 void                    *generic_sbp;
1045         } u;
1046         /*
1047 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs.h
1048 --- linux-2.4.21/include/linux/squashfs_fs.h    Thu Jan  1 01:00:00 1970
1049 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs.h        Tue Jul 29 03:15:06 2003
1050 @@ -0,0 +1,323 @@
1051 +#ifndef SQUASHFS_FS
1052 +#define SQUASHFS_FS
1053 +/*
1054 + * Squashfs
1055 + *
1056 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1057 + *
1058 + * This program is free software; you can redistribute it and/or
1059 + * modify it under the terms of the GNU General Public License
1060 + * as published by the Free Software Foundation; either version
1061 + * 2 of the License, or (at your option) any later version.
1062 + *
1063 + * squashfs_fs.h
1064 + */
1065 +
1066 +#define SQUASHFS_MAJOR                 1
1067 +#define SQUASHFS_MINOR                 0
1068 +#define SQUASHFS_MAGIC                 0x73717368
1069 +#define SQUASHFS_MAGIC_SWAP            0x68737173
1070 +#define SQUASHFS_START                 0
1071 +
1072 +/* size of metadata (inode and directory) blocks */
1073 +#define SQUASHFS_METADATA_SIZE         8192
1074 +#define SQUASHFS_METADATA_LOG          13
1075 +
1076 +/* default size of data blocks */
1077 +#define SQUASHFS_FILE_SIZE             32768
1078 +#define SQUASHFS_FILE_LOG              15
1079 +
1080 +#define SQUASHFS_FILE_MAX_SIZE         32768
1081 +
1082 +/* Max number of uids and gids */
1083 +#define SQUASHFS_UIDS                  48
1084 +#define SQUASHFS_GUIDS                 15
1085 +
1086 +/* Max length of filename (not 255) */
1087 +#define SQUASHFS_NAME_LEN              256
1088 +
1089 +#define SQUASHFS_INVALID               ((long long) 0xffffffffffff)
1090 +#define SQUASHFS_INVALID_BLK           ((long long) 0xffffffff)
1091 +#define SQUASHFS_USED_BLK              ((long long) 0xfffffffe)
1092 +
1093 +/* Filesystem flags */
1094 +#define SQUASHFS_NOI                   1
1095 +#define SQUASHFS_NOD                   2
1096 +#define SQUASHFS_CHECK                 4
1097 +#define SQUASHFS_UNCOMPRESSED_INODES(flags)    (flags & SQUASHFS_NOI)
1098 +#define SQUASHFS_UNCOMPRESSED_DATA(flags)      (flags & SQUASHFS_NOD)
1099 +#define SQUASHFS_CHECK_DATA(flags)             (flags & SQUASHFS_CHECK)
1100 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1101 +
1102 +/* Max number of types and file types */
1103 +#define SQUASHFS_TYPES                 5
1104 +#define SQUASHFS_DIR_TYPE              1
1105 +#define SQUASHFS_FILE_TYPE             2
1106 +#define SQUASHFS_SYMLINK_TYPE          3
1107 +#define SQUASHFS_BLKDEV_TYPE           4
1108 +#define SQUASHFS_CHRDEV_TYPE           5
1109 +
1110 +#define SQUASHFS_IPC_TYPE              0
1111 +#define SQUASHFS_FIFO_TYPE             6
1112 +#define SQUASHFS_SOCKET_TYPE           7
1113 +
1114 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1115 +#define SQUASHFS_COMPRESSED_BIT                (1 << 15)
1116 +#define SQUASHFS_COMPRESSED_SIZE(B)    (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1117 +                                       (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1118 +
1119 +#define SQUASHFS_COMPRESSED(B)         (!((B) & SQUASHFS_COMPRESSED_BIT))
1120 +
1121 +/*
1122 + * Inode number ops.  Inodes consist of a compressed block number, and an uncompressed
1123 + * offset within that block
1124 + */
1125 +#define SQUASHFS_INODE_BLK(a)          ((unsigned int) ((a) >> 16))
1126 +#define SQUASHFS_INODE_OFFSET(a)       ((unsigned int) ((a) & 0xffff))
1127 +#define SQUASHFS_MKINODE(A, B)         ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1128 +                                       + (B)))
1129 +
1130 +/* Compute 32 bit VFS inode number from squashfs inode number */
1131 +#define SQUASHFS_MK_VFS_INODE(a, b)    ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1132 +
1133 +/* Translate between VFS mode and squashfs mode */
1134 +#define SQUASHFS_MODE(a)               ((a) & 0xfff)
1135 +
1136 +/* cached data constants for filesystem */
1137 +#define SQUASHFS_CACHED_BLKS           8
1138 +
1139 +#define SQUASHFS_MAX_FILE_SIZE_LOG     32
1140 +#define SQUASHFS_MAX_FILE_SIZE         ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1141 +
1142 +#define SQUASHFS_MARKER_BYTE           0xff
1143 +
1144 +/*
1145 + * definitions for structures on disk
1146 + */
1147 +
1148 +typedef unsigned int           squashfs_block;
1149 +typedef long long              squashfs_inode;
1150 +
1151 +typedef unsigned int           squashfs_uid;
1152 +
1153 +typedef struct squashfs_super_block {
1154 +       unsigned int            s_magic;
1155 +       unsigned int            inodes;
1156 +       unsigned int            bytes_used;
1157 +       unsigned int            uid_start;
1158 +       unsigned int            guid_start;
1159 +       unsigned int            inode_table_start;
1160 +       unsigned int            directory_table_start;
1161 +       unsigned int            s_major:16;
1162 +       unsigned int            s_minor:16;
1163 +       unsigned int            block_size:16;
1164 +       unsigned int            block_log:16;
1165 +       unsigned int            flags:8;
1166 +       unsigned int            no_uids:8;
1167 +       unsigned int            no_guids:8;
1168 +       time_t                  mkfs_time /* time of filesystem creation */;
1169 +       squashfs_inode          root_inode;
1170 +} __attribute__ ((packed)) squashfs_super_block;
1171 +
1172 +typedef struct {
1173 +       unsigned int            inode_type:4;
1174 +       unsigned int            mode:12; /* protection */
1175 +       unsigned int            uid:4; /* index into uid table */
1176 +       unsigned int            guid:4; /* index into guid table */
1177 +} __attribute__ ((packed)) squashfs_base_inode_header;
1178 +
1179 +typedef struct {
1180 +       unsigned int            inode_type:4;
1181 +       unsigned int            mode:12; /* protection */
1182 +       unsigned int            uid:4; /* index into uid table */
1183 +       unsigned int            guid:4; /* index into guid table */
1184 +       unsigned int            type:4;
1185 +       unsigned int            offset:4;
1186 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1187 +
1188 +typedef struct {
1189 +       unsigned int            inode_type:4;
1190 +       unsigned int            mode:12; /* protection */
1191 +       unsigned int            uid:4; /* index into uid table */
1192 +       unsigned int            guid:4; /* index into guid table */
1193 +       unsigned short          rdev;
1194 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1195 +       
1196 +typedef struct {
1197 +       unsigned int            inode_type:4;
1198 +       unsigned int            mode:12; /* protection */
1199 +       unsigned int            uid:4; /* index into uid table */
1200 +       unsigned int            guid:4; /* index into guid table */
1201 +       unsigned short          symlink_size;
1202 +       char                    symlink[0];
1203 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1204 +
1205 +typedef struct {
1206 +       unsigned int            inode_type:4;
1207 +       unsigned int            mode:12; /* protection */
1208 +       unsigned int            uid:4; /* index into uid table */
1209 +       unsigned int            guid:4; /* index into guid table */
1210 +       time_t                  mtime;
1211 +       squashfs_block          start_block;
1212 +       unsigned int            file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1213 +       unsigned short          block_list[0];
1214 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1215 +
1216 +typedef struct {
1217 +       unsigned int            inode_type:4;
1218 +       unsigned int            mode:12; /* protection */
1219 +       unsigned int            uid:4; /* index into uid table */
1220 +       unsigned int            guid:4; /* index into guid table */
1221 +       unsigned int            file_size:19;
1222 +       unsigned int            offset:13;
1223 +       time_t                  mtime;
1224 +       unsigned int            start_block:24;
1225 +} __attribute__  ((packed)) squashfs_dir_inode_header;
1226 +
1227 +typedef union {
1228 +       squashfs_base_inode_header      base;
1229 +       squashfs_dev_inode_header       dev;
1230 +       squashfs_symlink_inode_header   symlink;
1231 +       squashfs_reg_inode_header       reg;
1232 +       squashfs_dir_inode_header       dir;
1233 +       squashfs_ipc_inode_header       ipc;
1234 +} squashfs_inode_header;
1235 +       
1236 +typedef struct {
1237 +       unsigned int            offset:13;
1238 +       unsigned int            type:3;
1239 +       unsigned int            size:8;
1240 +       char                    name[0];
1241 +} __attribute__ ((packed)) squashfs_dir_entry;
1242 +
1243 +typedef struct {
1244 +       unsigned int            count:8;
1245 +       unsigned int            start_block:24;
1246 +} __attribute__ ((packed)) squashfs_dir_header;
1247 +
1248 +
1249 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1250 +extern int squashfs_uncompress_init(void);
1251 +extern int squashfs_uncompress_exit(void);
1252 +
1253 +/*
1254 + * macros to convert each packed bitfield structure from little endian to big
1255 + * endian and vice versa.  These are needed when creating or using a filesystem on a
1256 + * machine with different byte ordering to the target architecture.
1257 + *
1258 + */
1259 +
1260 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1261 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1262 +       SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1263 +       SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1264 +       SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1265 +       SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1266 +       SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1267 +       SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1268 +       SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1269 +       SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1270 +       SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1271 +       SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1272 +       SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1273 +       SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1274 +       SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1275 +       SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1276 +       SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1277 +       SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1278 +}
1279 +
1280 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1281 +       SQUASHFS_MEMSET(s, d, n);\
1282 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1283 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1284 +       SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1285 +       SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1286 +}
1287 +
1288 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1289 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1290 +       SQUASHFS_SWAP((s)->type, d, 24, 4);\
1291 +       SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1292 +}
1293 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1294 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1295 +       SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1296 +}
1297 +
1298 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1299 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1300 +       SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1301 +}
1302 +
1303 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1304 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1305 +       SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1306 +       SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1307 +       SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1308 +}
1309 +
1310 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1311 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1312 +       SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1313 +       SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1314 +       SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1315 +       SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1316 +}
1317 +
1318 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1319 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1320 +       SQUASHFS_SWAP((s)->count, d, 0, 8);\
1321 +       SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1322 +}
1323 +
1324 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1325 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1326 +       SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1327 +       SQUASHFS_SWAP((s)->type, d, 13, 3);\
1328 +       SQUASHFS_SWAP((s)->size, d, 16, 8);\
1329 +}
1330 +
1331 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1332 +       int entry;\
1333 +       int bit_position;\
1334 +       SQUASHFS_MEMSET(s, d, n * 2);\
1335 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1336 +               SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1337 +}
1338 +
1339 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1340 +       int entry;\
1341 +       int bit_position;\
1342 +       SQUASHFS_MEMSET(s, d, n * bits / 8);\
1343 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1344 +               SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1345 +}
1346 +
1347 +#ifdef __KERNEL__
1348 +/*
1349 + * macros used to swap each structure entry, taking into account
1350 + * bitfields and different bitfield placing conventions on differing architectures
1351 + */
1352 +#include <asm/byteorder.h>
1353 +#ifdef __BIG_ENDIAN
1354 +       /* convert from little endian to big endian */
1355 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1356 +#else
1357 +       /* convert from big endian to little endian */ 
1358 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1359 +#endif
1360 +
1361 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1362 +       int bits;\
1363 +       int b_pos = pos % 8;\
1364 +       unsigned long long val = 0;\
1365 +       unsigned char *s = (unsigned char *)p + (pos / 8);\
1366 +       unsigned char *d = ((unsigned char *) &val) + 7;\
1367 +       for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1368 +               *d-- = *s++;\
1369 +       value = (val >> (SHIFT));\
1370 +}
1371 +#define SQUASHFS_MEMSET(s, d, n)       memset(s, 0, n);
1372 +#endif
1373 +#endif
1374 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs_i.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_i.h
1375 --- linux-2.4.21/include/linux/squashfs_fs_i.h  Thu Jan  1 01:00:00 1970
1376 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_i.h      Tue Jul 29 03:15:06 2003
1377 @@ -0,0 +1,21 @@
1378 +#ifndef SQUASHFS_FS_I
1379 +#define SQUASHFS_FS_I
1380 +/*
1381 + * Squashfs
1382 + *
1383 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1384 + *
1385 + * This program is free software; you can redistribute it and/or
1386 + * modify it under the terms of the GNU General Public License
1387 + * as published by the Free Software Foundation; either version
1388 + * 2 of the License, or (at your option) any later version.
1389 + *
1390 + * squashfs_fs_i.h
1391 + */
1392 +
1393 +typedef struct squashfs_inode_info {
1394 +       unsigned int    start_block;
1395 +       unsigned int    block_list_start;
1396 +       unsigned int    offset;
1397 +       } squashfs_inode_info;
1398 +#endif
1399 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs_sb.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_sb.h
1400 --- linux-2.4.21/include/linux/squashfs_fs_sb.h Thu Jan  1 01:00:00 1970
1401 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_sb.h     Tue Jul 29 03:15:06 2003
1402 @@ -0,0 +1,41 @@
1403 +#ifndef SQUASHFS_FS_SB
1404 +#define SQUASHFS_FS_SB
1405 +/*
1406 + * Squashfs
1407 + *
1408 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1409 + *
1410 + * This program is free software; you can redistribute it and/or
1411 + * modify it under the terms of the GNU General Public License
1412 + * as published by the Free Software Foundation; either version
1413 + * 2 of the License, or (at your option) any later version.
1414 + *
1415 + * squashfs_fs_sb.h
1416 + */
1417 +
1418 +#include <linux/squashfs_fs.h>
1419 +
1420 +typedef struct {
1421 +       unsigned int    block;
1422 +       int             length;
1423 +       unsigned int    next_index;
1424 +       char            *data;
1425 +       } squashfs_cache;
1426 +
1427 +typedef struct squashfs_sb_info {
1428 +       squashfs_super_block    sBlk;
1429 +       int                     devblksize;
1430 +       int                     devblksize_log2;
1431 +       int                     swap;
1432 +       squashfs_cache          *block_cache;
1433 +       int                     next_cache;
1434 +       squashfs_uid            *uid;
1435 +       squashfs_uid            *guid;
1436 +       unsigned int            read_size;
1437 +       char                    *read_data;
1438 +       char                    *read_page;
1439 +       struct semaphore        read_page_mutex;
1440 +       struct semaphore        block_cache_mutex;
1441 +       wait_queue_head_t       waitq;
1442 +       } squashfs_sb_info;
1443 +#endif
1444 diff --new-file -ur linux-2.4.21/init/do_mounts.c linux-2.4.21-squashfs1.3/init/do_mounts.c
1445 --- linux-2.4.21/init/do_mounts.c       Fri Jun 13 15:51:39 2003
1446 +++ linux-2.4.21-squashfs1.3/init/do_mounts.c   Tue Jul 29 03:15:06 2003
1447 @@ -15,6 +15,7 @@
1448  #include <linux/ext2_fs.h>
1449  #include <linux/romfs_fs.h>
1450  #include <linux/cramfs_fs.h>
1451 +#include <linux/squashfs_fs.h>
1452  
1453  #define BUILD_CRAMDISK
1454  
1455 @@ -475,6 +476,7 @@
1456   *     romfs
1457   *     cram
1458   *     gzip
1459 + *     squashfs
1460   */
1461  static int __init 
1462  identify_ramdisk_image(int fd, int start_block)
1463 @@ -483,6 +485,7 @@
1464         struct ext2_super_block *ext2sb;
1465         struct romfs_super_block *romfsb;
1466         struct cramfs_super *cramfsb;
1467 +       struct squashfs_super_block *squashfsb;
1468         int nblocks = -1;
1469         unsigned char *buf;
1470  
1471 @@ -493,6 +496,7 @@
1472         ext2sb = (struct ext2_super_block *) buf;
1473         romfsb = (struct romfs_super_block *) buf;
1474         cramfsb = (struct cramfs_super *) buf;
1475 +       squashfsb = (struct squashfs_super_block *) buf;
1476         memset(buf, 0xe5, size);
1477  
1478         /*
1479 @@ -522,6 +526,15 @@
1480                 goto done;
1481         }
1482  
1483 +       /* squashfs is at block zero too */
1484 +       if (squashfsb->s_magic == SQUASHFS_MAGIC) {
1485 +               printk(KERN_NOTICE
1486 +                      "RAMDISK: squashfs filesystem found at block %d\n",
1487 +                      start_block);
1488 +               nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
1489 +               goto done;
1490 +       }
1491 +
1492         /*
1493          * Read block 1 to test for minix and ext2 superblock
1494          */
1495 diff --new-file -ur linux-2.4.21/lib/Config.in linux-2.4.21-squashfs1.3/lib/Config.in
1496 --- linux-2.4.21/lib/Config.in  Thu Nov 28 23:53:15 2002
1497 +++ linux-2.4.21-squashfs1.3/lib/Config.in      Tue Jul 29 03:15:06 2003
1498 @@ -8,14 +8,16 @@
1499  # Do we need the compression support?
1500  #
1501  if [ "$CONFIG_CRAMFS" = "y" -o \
1502 +     "$CONFIG_SQUASHFS" = "y" -o \
1503       "$CONFIG_PPP_DEFLATE" = "y" -o \
1504       "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
1505       "$CONFIG_JFFS2_FS" = "y" -o \
1506       "$CONFIG_ZISOFS_FS" = "y" ]; then
1507     define_tristate CONFIG_ZLIB_INFLATE y
1508  else
1509    if [ "$CONFIG_CRAMFS" = "m" -o \
1510 +       "$CONFIG_SQUASHFS" = "m" -o \
1511         "$CONFIG_PPP_DEFLATE" = "m" -o \
1512         "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
1513         "$CONFIG_JFFS2_FS" = "m" -o \
1514         "$CONFIG_ZISOFS_FS" = "m" ]; then
This page took 0.158018 seconds and 3 git commands to generate.