reiserfs: Fix unwanted recursive reiserfs lock in reiserfs_unlink()
[safe/jmp/linux-2.6] / fs / isofs / compress.c
index 34a44e4..defb932 100644 (file)
@@ -16,7 +16,6 @@
  * Transparent decompression of files on an iso9660 filesystem
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 
@@ -34,7 +33,7 @@ static char zisofs_sink_page[PAGE_CACHE_SIZE];
  * allocation; this avoids failures at block-decompression time.
  */
 static void *zisofs_zlib_workspace;
-static struct semaphore zisofs_zlib_semaphore;
+static DEFINE_MUTEX(zisofs_zlib_lock);
 
 /*
  * When decompressing, we typically obtain more than one page
@@ -43,7 +42,7 @@ static struct semaphore zisofs_zlib_semaphore;
  */
 static int zisofs_readpage(struct file *file, struct page *page)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
        struct address_space *mapping = inode->i_mapping;
        unsigned int maxpage, xpage, fpage, blockindex;
        unsigned long offset;
@@ -73,6 +72,17 @@ static int zisofs_readpage(struct file *file, struct page *page)
        offset = index & ~zisofs_block_page_mask;
        blockindex = offset >> zisofs_block_page_shift;
        maxpage = (inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+
+       /*
+        * If this page is wholly outside i_size we just return zero;
+        * do_generic_file_read() will handle this for us
+        */
+       if (page->index >= maxpage) {
+               SetPageUptodate(page);
+               unlock_page(page);
+               return 0;
+       }
+
        maxpage = min(zisofs_block_pages, maxpage-offset);
 
        for ( i = 0 ; i < maxpage ; i++, offset++ ) {
@@ -129,8 +139,14 @@ static int zisofs_readpage(struct file *file, struct page *page)
        cend = le32_to_cpu(*(__le32 *)(bh->b_data + (blockendptr & bufmask)));
        brelse(bh);
 
+       if (cstart > cend)
+               goto eio;
+               
        csize = cend-cstart;
 
+       if (csize > deflateBound(1UL << zisofs_block_shift))
+               goto eio;
+
        /* Now page[] contains an array of pages, any of which can be NULL,
           and the locks on which we hold.  We should now read the data and
           release the pages.  If the pages are NULL the decompressed data
@@ -175,9 +191,9 @@ static int zisofs_readpage(struct file *file, struct page *page)
 
                /* First block is special since it may be fractional.
                   We also wait for it before grabbing the zlib
-                  semaphore; odds are that the subsequent blocks are
+                  mutex; odds are that the subsequent blocks are
                   going to come in in short order so we don't hold
-                  the zlib semaphore longer than necessary. */
+                  the zlib mutex longer than necessary. */
 
                if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
                        printk(KERN_DEBUG "zisofs: Hit null buffer, fpage = %d, xpage = %d, csize = %ld\n",
@@ -189,7 +205,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
                csize -= stream.avail_in;
 
                stream.workspace = zisofs_zlib_workspace;
-               down(&zisofs_zlib_semaphore);
+               mutex_lock(&zisofs_zlib_lock);
                
                zerr = zlib_inflateInit(&stream);
                if ( zerr != Z_OK ) {
@@ -276,7 +292,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
                zlib_inflateEnd(&stream);
 
        z_eio:
-               up(&zisofs_zlib_semaphore);
+               mutex_unlock(&zisofs_zlib_lock);
 
        b_eio:
                for ( i = 0 ; i < haveblocks ; i++ ) {
@@ -306,37 +322,22 @@ eio:
        return err;
 }
 
-struct address_space_operations zisofs_aops = {
+const struct address_space_operations zisofs_aops = {
        .readpage = zisofs_readpage,
        /* No sync_page operation supported? */
        /* No bmap operation supported */
 };
 
-static int initialized;
-
 int __init zisofs_init(void)
 {
-       if ( initialized ) {
-               printk("zisofs_init: called more than once\n");
-               return 0;
-       }
-
        zisofs_zlib_workspace = vmalloc(zlib_inflate_workspacesize());
        if ( !zisofs_zlib_workspace )
                return -ENOMEM;
-       init_MUTEX(&zisofs_zlib_semaphore);
 
-       initialized = 1;
        return 0;
 }
 
 void zisofs_cleanup(void)
 {
-       if ( !initialized ) {
-               printk("zisofs_cleanup: called without initialization\n");
-               return;
-       }
-
        vfree(zisofs_zlib_workspace);
-       initialized = 0;
 }