LCOV - code coverage report
Current view: top level - fs/cramfs - uncompress.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 30 0.0 %
Date: 2014-02-18 Functions: 0 3 0.0 %
Branches: 0 10 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * uncompress.c
       3                 :            :  *
       4                 :            :  * (C) Copyright 1999 Linus Torvalds
       5                 :            :  *
       6                 :            :  * cramfs interfaces to the uncompression library. There's really just
       7                 :            :  * three entrypoints:
       8                 :            :  *
       9                 :            :  *  - cramfs_uncompress_init() - called to initialize the thing.
      10                 :            :  *  - cramfs_uncompress_exit() - tell me when you're done
      11                 :            :  *  - cramfs_uncompress_block() - uncompress a block.
      12                 :            :  *
      13                 :            :  * NOTE NOTE NOTE! The uncompression is entirely single-threaded. We
      14                 :            :  * only have one stream, and we'll initialize it only once even if it
      15                 :            :  * then is used by multiple filesystems.
      16                 :            :  */
      17                 :            : 
      18                 :            : #include <linux/kernel.h>
      19                 :            : #include <linux/errno.h>
      20                 :            : #include <linux/vmalloc.h>
      21                 :            : #include <linux/zlib.h>
      22                 :            : #include <linux/cramfs_fs.h>
      23                 :            : 
      24                 :            : static z_stream stream;
      25                 :            : static int initialized;
      26                 :            : 
      27                 :            : /* Returns length of decompressed data. */
      28                 :          0 : int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen)
      29                 :            : {
      30                 :            :         int err;
      31                 :            : 
      32                 :          0 :         stream.next_in = src;
      33                 :          0 :         stream.avail_in = srclen;
      34                 :            : 
      35                 :          0 :         stream.next_out = dst;
      36                 :          0 :         stream.avail_out = dstlen;
      37                 :            : 
      38                 :          0 :         err = zlib_inflateReset(&stream);
      39         [ #  # ]:          0 :         if (err != Z_OK) {
      40                 :          0 :                 printk("zlib_inflateReset error %d\n", err);
      41                 :          0 :                 zlib_inflateEnd(&stream);
      42                 :          0 :                 zlib_inflateInit(&stream);
      43                 :            :         }
      44                 :            : 
      45                 :          0 :         err = zlib_inflate(&stream, Z_FINISH);
      46         [ #  # ]:          0 :         if (err != Z_STREAM_END)
      47                 :            :                 goto err;
      48                 :          0 :         return stream.total_out;
      49                 :            : 
      50                 :            : err:
      51                 :          0 :         printk("Error %d while decompressing!\n", err);
      52                 :          0 :         printk("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
      53                 :          0 :         return -EIO;
      54                 :            : }
      55                 :            : 
      56                 :          0 : int cramfs_uncompress_init(void)
      57                 :            : {
      58         [ #  # ]:          0 :         if (!initialized++) {
      59                 :          0 :                 stream.workspace = vmalloc(zlib_inflate_workspacesize());
      60         [ #  # ]:          0 :                 if ( !stream.workspace ) {
      61                 :          0 :                         initialized = 0;
      62                 :          0 :                         return -ENOMEM;
      63                 :            :                 }
      64                 :          0 :                 stream.next_in = NULL;
      65                 :          0 :                 stream.avail_in = 0;
      66                 :          0 :                 zlib_inflateInit(&stream);
      67                 :            :         }
      68                 :            :         return 0;
      69                 :            : }
      70                 :            : 
      71                 :          0 : void cramfs_uncompress_exit(void)
      72                 :            : {
      73         [ #  # ]:          0 :         if (!--initialized) {
      74                 :          0 :                 zlib_inflateEnd(&stream);
      75                 :          0 :                 vfree(stream.workspace);
      76                 :            :         }
      77                 :          0 : }

Generated by: LCOV version 1.9