Squashfs: factor out remaining zlib dependencies into separate wrapper file
[safe/jmp/linux-2.6] / fs / squashfs / super.c
index a0466d7..b9f8c6a 100644 (file)
 #include <linux/fs.h>
 #include <linux/vfs.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/mutex.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/zlib.h>
+#include <linux/magic.h>
 
 #include "squashfs_fs.h"
 #include "squashfs_fs_sb.h"
@@ -42,7 +43,7 @@
 #include "squashfs.h"
 
 static struct file_system_type squashfs_fs_type;
-static struct super_operations squashfs_super_ops;
+static const struct super_operations squashfs_super_ops;
 
 static int supported_squashfs_filesystem(short major, short minor, short comp)
 {
@@ -85,12 +86,9 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
        }
        msblk = sb->s_fs_info;
 
-       msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
-               GFP_KERNEL);
-       if (msblk->stream.workspace == NULL) {
-               ERROR("Failed to allocate zlib workspace\n");
+       msblk->stream = squashfs_zlib_init();
+       if (msblk->stream == NULL)
                goto failure;
-       }
 
        sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
        if (sblk == NULL) {
@@ -156,6 +154,16 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
        if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE)
                goto failed_mount;
 
+       /*
+        * Check the system page size is not larger than the filesystem
+        * block size (by default 128K).  This is currently not supported.
+        */
+       if (PAGE_CACHE_SIZE > msblk->block_size) {
+               ERROR("Page size > filesystem block size (%d).  This is "
+                       "currently not supported!\n", msblk->block_size);
+               goto failed_mount;
+       }
+
        msblk->block_log = le16_to_cpu(sblk->block_log);
        if (msblk->block_log > SQUASHFS_FILE_MAX_LOG)
                goto failed_mount;
@@ -280,17 +288,17 @@ failed_mount:
        squashfs_cache_delete(msblk->block_cache);
        squashfs_cache_delete(msblk->fragment_cache);
        squashfs_cache_delete(msblk->read_page);
+       squashfs_zlib_free(msblk->stream);
        kfree(msblk->inode_lookup_table);
        kfree(msblk->fragment_index);
        kfree(msblk->id_table);
-       kfree(msblk->stream.workspace);
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
        kfree(sblk);
        return err;
 
 failure:
-       kfree(msblk->stream.workspace);
+       squashfs_zlib_free(msblk->stream);
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
        return -ENOMEM;
@@ -300,6 +308,7 @@ failure:
 static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
        struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
+       u64 id = huge_encode_dev(dentry->d_sb->s_bdev->bd_dev);
 
        TRACE("Entered squashfs_statfs\n");
 
@@ -310,6 +319,8 @@ static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_files = msblk->inodes;
        buf->f_ffree = 0;
        buf->f_namelen = SQUASHFS_NAME_LEN;
+       buf->f_fsid.val[0] = (u32)id;
+       buf->f_fsid.val[1] = (u32)(id >> 32);
 
        return 0;
 }
@@ -324,18 +335,22 @@ static int squashfs_remount(struct super_block *sb, int *flags, char *data)
 
 static void squashfs_put_super(struct super_block *sb)
 {
+       lock_kernel();
+
        if (sb->s_fs_info) {
                struct squashfs_sb_info *sbi = sb->s_fs_info;
                squashfs_cache_delete(sbi->block_cache);
                squashfs_cache_delete(sbi->fragment_cache);
                squashfs_cache_delete(sbi->read_page);
+               squashfs_zlib_free(sbi->stream);
                kfree(sbi->id_table);
                kfree(sbi->fragment_index);
                kfree(sbi->meta_index);
-               kfree(sbi->stream.workspace);
                kfree(sb->s_fs_info);
                sb->s_fs_info = NULL;
        }
+
+       unlock_kernel();
 }
 
 
@@ -388,7 +403,7 @@ static int __init init_squashfs_fs(void)
                return err;
        }
 
-       printk(KERN_INFO "squashfs: version 4.0 (2009/01/03) "
+       printk(KERN_INFO "squashfs: version 4.0 (2009/01/31) "
                "Phillip Lougher\n");
 
        return 0;
@@ -425,7 +440,7 @@ static struct file_system_type squashfs_fs_type = {
        .fs_flags = FS_REQUIRES_DEV
 };
 
-static struct super_operations squashfs_super_ops = {
+static const struct super_operations squashfs_super_ops = {
        .alloc_inode = squashfs_alloc_inode,
        .destroy_inode = squashfs_destroy_inode,
        .statfs = squashfs_statfs,