]> git.pld-linux.org Git - packages/kernel.git/blame - squashfs1.3r2-patch
- added description of djurban's branch
[packages/kernel.git] / squashfs1.3r2-patch
CommitLineData
cbea2c31
AM
1diff --new-file -ur linux-2.6.0-test7/fs/Kconfig linux-2.6.0-test7-squashfs1.3r2/fs/Kconfig
2--- linux-2.6.0-test7/fs/Kconfig 2003-10-08 20:24:14.000000000 +0100
3+++ linux-2.6.0-test7-squashfs1.3r2/fs/Kconfig 2003-10-14 02:37:09.000000000 +0100
4@@ -1113,6 +1113,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.0-test7/fs/Makefile linux-2.6.0-test7-squashfs1.3r2/fs/Makefile
35--- linux-2.6.0-test7/fs/Makefile 2003-10-08 20:24:14.000000000 +0100
36+++ linux-2.6.0-test7-squashfs1.3r2/fs/Makefile 2003-10-14 02:37:09.000000000 +0100
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.0-test7/fs/squashfs/inode.c linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/inode.c
46--- linux-2.6.0-test7/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
47+++ linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/inode.c 2003-10-14 02:37:09.000000000 +0100
48@@ -0,0 +1,1063 @@
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+
702+ TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
703+ page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(i)->offset);
704+
705+ for(length = 0; length < index; length += bytes) {
706+ if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
707+ PAGE_CACHE_SIZE, &block, &offset))) {
708+ ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
709+ goto skip_read;
710+ }
711+ }
712+
713+ if(length != index) {
714+ ERROR("(squashfs_symlink_readpage) length != index\n");
715+ return 0;
716+ }
717+
718+ bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
719+ if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
720+ ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
721+
722+skip_read:
723+ memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
724+ flush_dcache_page(page);
725+ SetPageUptodate(page);
726+ unlock_page(page);
727+
728+ return 0;
729+}
730+
731+
732+#define SIZE 256
733+static int squashfs_readpage(struct file *file, struct page *page)
734+{
735+ struct inode *inode = page->mapping->host;
736+ squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
737+ squashfs_super_block *sBlk = &msBlk->sBlk;
738+ unsigned char block_list[SIZE];
739+ unsigned short *block_listp;
740+ int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
741+ page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
742+ page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
743+ int block = SQUASHFS_I(inode)->start_block, i = 0;
744+ int bytes = 0, block_ptr = SQUASHFS_I(inode)->block_list_start;
745+ int offset = SQUASHFS_I(inode)->offset;
746+ int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
747+ int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
748+
749+ TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
750+ SQUASHFS_I(inode)->start_block);
751+
752+ if(index > file_blocks)
753+ goto skip_read;
754+
755+ for(;;) {
756+ int blocks = (index + readahead_blks - i);
757+ if(blocks > (SIZE >> 1)) {
758+ if((index - i) <= (SIZE >> 1))
759+ blocks = index - i;
760+ else
761+ blocks = SIZE >> 1;
762+ }
763+
764+ if(msBlk->swap) {
765+ unsigned char sblock_list[SIZE];
766+ if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
767+ ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
768+ goto skip_read;
769+ }
770+ SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
771+ } else
772+ if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
773+ ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
774+ goto skip_read;
775+ }
776+ for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
777+ block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
778+ if(blocks >= readahead_blks)
779+ break;
780+ }
781+
782+ if(sBlk->block_log > PAGE_CACHE_SHIFT) {
783+ int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
784+ int start_index = page->index & ~mask;
785+ int end_index = start_index | mask;
786+ int byte_offset = 0;
787+
788+ down(&msBlk->read_page_mutex);
789+ if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
790+ ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
791+ goto skip_read;
792+ }
793+
794+ for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
795+ int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
796+
797+ TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
798+
799+ if(i == page->index) {
800+ memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
801+ memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
802+ flush_dcache_page(page);
803+ SetPageUptodate(page);
804+ unlock_page(page);
805+ } else {
806+ struct page *push_page;
807+
808+ if((push_page = grab_cache_page_nowait(page->mapping, i))) {
809+ memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
810+ memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
811+ flush_dcache_page(push_page);
812+ SetPageUptodate(push_page);
813+ unlock_page(push_page);
814+ page_cache_release(push_page);
815+ }
816+ }
817+ }
818+ up( &msBlk->read_page_mutex);
819+
820+ return 0;
821+
822+ } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
823+ if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
824+ ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
825+
826+ } else {
827+ int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
828+ char *p = (char *) page_address(page);
829+ int byte;
830+
831+ if(i_end > file_blocks)
832+ i_end = file_blocks;
833+
834+ while(index < i_end) {
835+ if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
836+ ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
837+ goto skip_read;
838+ }
839+ block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
840+ p += byte;
841+ bytes += byte;
842+ index ++;
843+ block_listp ++;
844+ }
845+ }
846+
847+skip_read:
848+ memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
849+ flush_dcache_page(page);
850+ SetPageUptodate(page);
851+ unlock_page(page);
852+
853+ return 0;
854+}
855+
856+
857+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
858+{
859+ struct inode *i = file->f_dentry->d_inode;
860+ squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
861+ squashfs_super_block *sBlk = &msBlk->sBlk;
862+ int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
863+ SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
864+ squashfs_dir_header dirh;
865+ char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
866+ squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
867+
868+ TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
869+
870+ lock_kernel();
871+ while(length < i->i_size) {
872+ /* read directory header */
873+ if(msBlk->swap) {
874+ squashfs_dir_header sdirh;
875+ if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
876+ next_offset, sizeof(sdirh), &next_block, &next_offset))
877+ goto failed_read;
878+ length += sizeof(sdirh);
879+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
880+ } else {
881+ if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
882+ next_offset, sizeof(dirh), &next_block, &next_offset))
883+ goto failed_read;
884+ length += sizeof(dirh);
885+ }
886+
887+ dir_count = dirh.count + 1;
888+ while(dir_count--) {
889+ if(msBlk->swap) {
890+ squashfs_dir_entry sdire;
891+ if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
892+ next_offset, sizeof(sdire), &next_block, &next_offset))
893+ goto failed_read;
894+ length += sizeof(sdire);
895+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
896+ } else {
897+ if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
898+ next_offset, sizeof(*dire), &next_block, &next_offset))
899+ goto failed_read;
900+ length += sizeof(*dire);
901+ }
902+
903+ if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
904+ next_offset, dire->size + 1, &next_block, &next_offset))
905+ goto failed_read;
906+ length += dire->size + 1;
907+
908+ if(file->f_pos >= length)
909+ continue;
910+
911+ dire->name[dire->size + 1] = '\0';
912+
913+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
914+ dire->name, dire->size + 1, (int) file->f_pos,
915+ dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
916+
917+ if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
918+ dire->offset), squashfs_filetype_table[dire->type]) < 0) {
919+ TRACE("Filldir returned less than 0\n");
920+ unlock_kernel();
921+ return dirs_read;
922+ }
923+
924+ file->f_pos = length;
925+ dirs_read ++;
926+ }
927+ }
928+
929+ unlock_kernel();
930+ return dirs_read;
931+
932+failed_read:
933+ unlock_kernel();
934+ ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
935+ return 0;
936+}
937+
938+
939+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
940+{
941+ const char *name =dentry->d_name.name;
942+ int len = dentry->d_name.len;
943+ struct inode *inode = NULL;
944+ squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
945+ squashfs_super_block *sBlk = &msBlk->sBlk;
946+ int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
947+ SQUASHFS_I(i)->offset, length = 0, dir_count;
948+ squashfs_dir_header dirh;
949+ char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
950+ squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
951+
952+ TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
953+
954+ lock_kernel();
955+ while(length < i->i_size) {
956+ /* read directory header */
957+ if(msBlk->swap) {
958+ squashfs_dir_header sdirh;
959+ if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
960+ sizeof(sdirh), &next_block, &next_offset))
961+ goto failed_read;
962+ length += sizeof(sdirh);
963+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
964+ } else {
965+ if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
966+ sizeof(dirh), &next_block, &next_offset))
967+ goto failed_read;
968+ length += sizeof(dirh);
969+ }
970+
971+ dir_count = dirh.count + 1;
972+ while(dir_count--) {
973+ if(msBlk->swap) {
974+ squashfs_dir_entry sdire;
975+ if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
976+ next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
977+ goto failed_read;
978+ length += sizeof(sdire);
979+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
980+ } else {
981+ if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
982+ next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
983+ goto failed_read;
984+ length += sizeof(*dire);
985+ }
986+
987+ if(!squashfs_get_cached_block(i->i_sb, dire->name,
988+ next_block, next_offset, dire->size + 1, &next_block, &next_offset))
989+ goto failed_read;
990+ length += dire->size + 1;
991+
992+ if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
993+ squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
994+
995+ TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
996+ name, dirh.start_block, dire->offset);
997+
998+ inode = squashfs_iget(i->i_sb, ino);
999+
1000+ goto exit_loop;
1001+ }
1002+ }
1003+ }
1004+
1005+exit_loop:
1006+ d_add(dentry, inode);
1007+ unlock_kernel();
1008+ return ERR_PTR(0);
1009+
1010+failed_read:
1011+ ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1012+ goto exit_loop;
1013+}
1014+
1015+
1016+static void squashfs_put_super(struct super_block *s)
1017+{
1018+ if(s->s_fs_info) {
1019+ squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1020+ if(sbi->block_cache) kfree(sbi->block_cache);
1021+ if(sbi->read_data) kfree(sbi->read_data);
1022+ if(sbi->read_page) kfree(sbi->read_page);
1023+ if(sbi->uid) kfree(sbi->uid);
1024+ kfree(s->s_fs_info);
1025+ s->s_fs_info = NULL;
1026+ }
1027+}
1028+
1029+
1030+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1031+{
1032+ return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1033+}
1034+
1035+
1036+static int __init init_squashfs_fs(void)
1037+{
1038+ int err = init_inodecache();
1039+ if(err)
1040+ return err;
1041+
1042+ if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1043+ ERROR("Failed to allocate zlib workspace\n");
1044+ destroy_inodecache();
1045+ return -ENOMEM;
1046+ }
1047+
1048+ if((err = register_filesystem(&squashfs_fs_type))) {
1049+ vfree(stream.workspace);
1050+ destroy_inodecache();
1051+ }
1052+
1053+ return err;
1054+}
1055+
1056+
1057+static void __exit exit_squashfs_fs(void)
1058+{
1059+ vfree(stream.workspace);
1060+ unregister_filesystem(&squashfs_fs_type);
1061+ destroy_inodecache();
1062+}
1063+
1064+
1065+static kmem_cache_t * squashfs_inode_cachep;
1066+
1067+static struct inode *squashfs_alloc_inode(struct super_block *sb)
1068+{
1069+ struct squashfs_inode_info *ei;
1070+ ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1071+ if (!ei)
1072+ return NULL;
1073+ return &ei->vfs_inode;
1074+}
1075+
1076+static void squashfs_destroy_inode(struct inode *inode)
1077+{
1078+ kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1079+}
1080+
1081+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1082+{
1083+ struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1084+
1085+ if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1086+ SLAB_CTOR_CONSTRUCTOR)
1087+ inode_init_once(&ei->vfs_inode);
1088+}
1089+
1090+static int init_inodecache(void)
1091+{
1092+ squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1093+ sizeof(struct squashfs_inode_info),
1094+ 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1095+ init_once, NULL);
1096+ if (squashfs_inode_cachep == NULL)
1097+ return -ENOMEM;
1098+ return 0;
1099+}
1100+
1101+static void destroy_inodecache(void)
1102+{
1103+ if (kmem_cache_destroy(squashfs_inode_cachep))
1104+ printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1105+}
1106+
1107+module_init(init_squashfs_fs);
1108+module_exit(exit_squashfs_fs);
1109+MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1110+MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1111+MODULE_LICENSE("GPL");
1112diff --new-file -ur linux-2.6.0-test7/fs/squashfs/Makefile linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/Makefile
1113--- linux-2.6.0-test7/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
1114+++ linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/Makefile 2003-10-14 02:37:09.000000000 +0100
1115@@ -0,0 +1,7 @@
1116+#
1117+# Makefile for the linux squashfs routines.
1118+#
1119+
1120+obj-$(CONFIG_SQUASHFS) += squashfs.o
1121+
1122+squashfs-objs := inode.o
1123diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs.h
1124--- linux-2.6.0-test7/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
1125+++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs.h 2003-10-14 02:37:09.000000000 +0100
1126@@ -0,0 +1,323 @@
1127+#ifndef SQUASHFS_FS
1128+#define SQUASHFS_FS
1129+/*
1130+ * Squashfs
1131+ *
1132+ * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1133+ *
1134+ * This program is free software; you can redistribute it and/or
1135+ * modify it under the terms of the GNU General Public License
1136+ * as published by the Free Software Foundation; either version
1137+ * 2 of the License, or (at your option) any later version.
1138+ *
1139+ * squashfs_fs.h
1140+ */
1141+
1142+#define SQUASHFS_MAJOR 1
1143+#define SQUASHFS_MINOR 0
1144+#define SQUASHFS_MAGIC 0x73717368
1145+#define SQUASHFS_MAGIC_SWAP 0x68737173
1146+#define SQUASHFS_START 0
1147+
1148+/* size of metadata (inode and directory) blocks */
1149+#define SQUASHFS_METADATA_SIZE 8192
1150+#define SQUASHFS_METADATA_LOG 13
1151+
1152+/* default size of data blocks */
1153+#define SQUASHFS_FILE_SIZE 32768
1154+#define SQUASHFS_FILE_LOG 15
1155+
1156+#define SQUASHFS_FILE_MAX_SIZE 32768
1157+
1158+/* Max number of uids and gids */
1159+#define SQUASHFS_UIDS 48
1160+#define SQUASHFS_GUIDS 15
1161+
1162+/* Max length of filename (not 255) */
1163+#define SQUASHFS_NAME_LEN 256
1164+
1165+#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1166+#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1167+#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1168+
1169+/* Filesystem flags */
1170+#define SQUASHFS_NOI 1
1171+#define SQUASHFS_NOD 2
1172+#define SQUASHFS_CHECK 4
1173+#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1174+#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1175+#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1176+#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1177+
1178+/* Max number of types and file types */
1179+#define SQUASHFS_TYPES 5
1180+#define SQUASHFS_DIR_TYPE 1
1181+#define SQUASHFS_FILE_TYPE 2
1182+#define SQUASHFS_SYMLINK_TYPE 3
1183+#define SQUASHFS_BLKDEV_TYPE 4
1184+#define SQUASHFS_CHRDEV_TYPE 5
1185+
1186+#define SQUASHFS_IPC_TYPE 0
1187+#define SQUASHFS_FIFO_TYPE 6
1188+#define SQUASHFS_SOCKET_TYPE 7
1189+
1190+/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1191+#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1192+#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1193+ (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1194+
1195+#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1196+
1197+/*
1198+ * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1199+ * offset within that block
1200+ */
1201+#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1202+#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1203+#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1204+ + (B)))
1205+
1206+/* Compute 32 bit VFS inode number from squashfs inode number */
1207+#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1208+
1209+/* Translate between VFS mode and squashfs mode */
1210+#define SQUASHFS_MODE(a) ((a) & 0xfff)
1211+
1212+/* cached data constants for filesystem */
1213+#define SQUASHFS_CACHED_BLKS 8
1214+
1215+#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1216+#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1217+
1218+#define SQUASHFS_MARKER_BYTE 0xff
1219+
1220+/*
1221+ * definitions for structures on disk
1222+ */
1223+
1224+typedef unsigned int squashfs_block;
1225+typedef long long squashfs_inode;
1226+
1227+typedef unsigned int squashfs_uid;
1228+
1229+typedef struct squashfs_super_block {
1230+ unsigned int s_magic;
1231+ unsigned int inodes;
1232+ unsigned int bytes_used;
1233+ unsigned int uid_start;
1234+ unsigned int guid_start;
1235+ unsigned int inode_table_start;
1236+ unsigned int directory_table_start;
1237+ unsigned int s_major:16;
1238+ unsigned int s_minor:16;
1239+ unsigned int block_size:16;
1240+ unsigned int block_log:16;
1241+ unsigned int flags:8;
1242+ unsigned int no_uids:8;
1243+ unsigned int no_guids:8;
1244+ time_t mkfs_time /* time of filesystem creation */;
1245+ squashfs_inode root_inode;
1246+} __attribute__ ((packed)) squashfs_super_block;
1247+
1248+typedef struct {
1249+ unsigned int inode_type:4;
1250+ unsigned int mode:12; /* protection */
1251+ unsigned int uid:4; /* index into uid table */
1252+ unsigned int guid:4; /* index into guid table */
1253+} __attribute__ ((packed)) squashfs_base_inode_header;
1254+
1255+typedef struct {
1256+ unsigned int inode_type:4;
1257+ unsigned int mode:12; /* protection */
1258+ unsigned int uid:4; /* index into uid table */
1259+ unsigned int guid:4; /* index into guid table */
1260+ unsigned int type:4;
1261+ unsigned int offset:4;
1262+} __attribute__ ((packed)) squashfs_ipc_inode_header;
1263+
1264+typedef struct {
1265+ unsigned int inode_type:4;
1266+ unsigned int mode:12; /* protection */
1267+ unsigned int uid:4; /* index into uid table */
1268+ unsigned int guid:4; /* index into guid table */
1269+ unsigned short rdev;
1270+} __attribute__ ((packed)) squashfs_dev_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 symlink_size;
1278+ char symlink[0];
1279+} __attribute__ ((packed)) squashfs_symlink_inode_header;
1280+
1281+typedef struct {
1282+ unsigned int inode_type:4;
1283+ unsigned int mode:12; /* protection */
1284+ unsigned int uid:4; /* index into uid table */
1285+ unsigned int guid:4; /* index into guid table */
1286+ time_t mtime;
1287+ squashfs_block start_block;
1288+ unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1289+ unsigned short block_list[0];
1290+} __attribute__ ((packed)) squashfs_reg_inode_header;
1291+
1292+typedef struct {
1293+ unsigned int inode_type:4;
1294+ unsigned int mode:12; /* protection */
1295+ unsigned int uid:4; /* index into uid table */
1296+ unsigned int guid:4; /* index into guid table */
1297+ unsigned int file_size:19;
1298+ unsigned int offset:13;
1299+ time_t mtime;
1300+ unsigned int start_block:24;
1301+} __attribute__ ((packed)) squashfs_dir_inode_header;
1302+
1303+typedef union {
1304+ squashfs_base_inode_header base;
1305+ squashfs_dev_inode_header dev;
1306+ squashfs_symlink_inode_header symlink;
1307+ squashfs_reg_inode_header reg;
1308+ squashfs_dir_inode_header dir;
1309+ squashfs_ipc_inode_header ipc;
1310+} squashfs_inode_header;
1311+
1312+typedef struct {
1313+ unsigned int offset:13;
1314+ unsigned int type:3;
1315+ unsigned int size:8;
1316+ char name[0];
1317+} __attribute__ ((packed)) squashfs_dir_entry;
1318+
1319+typedef struct {
1320+ unsigned int count:8;
1321+ unsigned int start_block:24;
1322+} __attribute__ ((packed)) squashfs_dir_header;
1323+
1324+
1325+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1326+extern int squashfs_uncompress_init(void);
1327+extern int squashfs_uncompress_exit(void);
1328+
1329+/*
1330+ * macros to convert each packed bitfield structure from little endian to big
1331+ * endian and vice versa. These are needed when creating or using a filesystem on a
1332+ * machine with different byte ordering to the target architecture.
1333+ *
1334+ */
1335+
1336+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1337+ SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1338+ SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1339+ SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1340+ SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1341+ SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1342+ SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1343+ SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1344+ SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1345+ SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1346+ SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1347+ SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1348+ SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1349+ SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1350+ SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1351+ SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1352+ SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1353+ SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1354+}
1355+
1356+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1357+ SQUASHFS_MEMSET(s, d, n);\
1358+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1359+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1360+ SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1361+ SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1362+}
1363+
1364+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1365+ SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1366+ SQUASHFS_SWAP((s)->type, d, 24, 4);\
1367+ SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1368+}
1369+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1370+ SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1371+ SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1372+}
1373+
1374+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1375+ SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1376+ SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1377+}
1378+
1379+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1380+ SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1381+ SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1382+ SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1383+ SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1384+}
1385+
1386+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1387+ SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1388+ SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1389+ SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1390+ SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1391+ SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1392+}
1393+
1394+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1395+ SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1396+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
1397+ SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1398+}
1399+
1400+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1401+ SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1402+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1403+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
1404+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
1405+}
1406+
1407+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1408+ int entry;\
1409+ int bit_position;\
1410+ SQUASHFS_MEMSET(s, d, n * 2);\
1411+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1412+ SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1413+}
1414+
1415+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1416+ int entry;\
1417+ int bit_position;\
1418+ SQUASHFS_MEMSET(s, d, n * bits / 8);\
1419+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1420+ SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1421+}
1422+
1423+#ifdef __KERNEL__
1424+/*
1425+ * macros used to swap each structure entry, taking into account
1426+ * bitfields and different bitfield placing conventions on differing architectures
1427+ */
1428+#include <asm/byteorder.h>
1429+#ifdef __BIG_ENDIAN
1430+ /* convert from little endian to big endian */
1431+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1432+#else
1433+ /* convert from big endian to little endian */
1434+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1435+#endif
1436+
1437+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1438+ int bits;\
1439+ int b_pos = pos % 8;\
1440+ unsigned long long val = 0;\
1441+ unsigned char *s = (unsigned char *)p + (pos / 8);\
1442+ unsigned char *d = ((unsigned char *) &val) + 7;\
1443+ for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1444+ *d-- = *s++;\
1445+ value = (val >> (SHIFT));\
1446+}
1447+#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1448+#endif
1449+#endif
1450diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs_i.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_i.h
1451--- linux-2.6.0-test7/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
1452+++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_i.h 2003-10-14 02:37:09.000000000 +0100
1453@@ -0,0 +1,22 @@
1454+#ifndef SQUASHFS_FS_I
1455+#define SQUASHFS_FS_I
1456+/*
1457+ * Squashfs
1458+ *
1459+ * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1460+ *
1461+ * This program is free software; you can redistribute it and/or
1462+ * modify it under the terms of the GNU General Public License
1463+ * as published by the Free Software Foundation; either version
1464+ * 2 of the License, or (at your option) any later version.
1465+ *
1466+ * squashfs_fs_i.h
1467+ */
1468+
1469+typedef struct squashfs_inode_info {
1470+ unsigned int start_block;
1471+ unsigned int block_list_start;
1472+ unsigned int offset;
1473+ struct inode vfs_inode;
1474+ } squashfs_inode_info;
1475+#endif
1476diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs_sb.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_sb.h
1477--- linux-2.6.0-test7/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
1478+++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_sb.h 2003-10-14 02:37:09.000000000 +0100
1479@@ -0,0 +1,41 @@
1480+#ifndef SQUASHFS_FS_SB
1481+#define SQUASHFS_FS_SB
1482+/*
1483+ * Squashfs
1484+ *
1485+ * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1486+ *
1487+ * This program is free software; you can redistribute it and/or
1488+ * modify it under the terms of the GNU General Public License
1489+ * as published by the Free Software Foundation; either version
1490+ * 2 of the License, or (at your option) any later version.
1491+ *
1492+ * squashfs_fs_sb.h
1493+ */
1494+
1495+#include <linux/squashfs_fs.h>
1496+
1497+typedef struct {
1498+ unsigned int block;
1499+ int length;
1500+ unsigned int next_index;
1501+ char *data;
1502+ } squashfs_cache;
1503+
1504+typedef struct squashfs_sb_info {
1505+ squashfs_super_block sBlk;
1506+ int devblksize;
1507+ int devblksize_log2;
1508+ int swap;
1509+ squashfs_cache *block_cache;
1510+ int next_cache;
1511+ squashfs_uid *uid;
1512+ squashfs_uid *guid;
1513+ unsigned int read_size;
1514+ char *read_data;
1515+ char *read_page;
1516+ struct semaphore read_page_mutex;
1517+ struct semaphore block_cache_mutex;
1518+ wait_queue_head_t waitq;
1519+ } squashfs_sb_info;
1520+#endif
This page took 0.81526 seconds and 4 git commands to generate.