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