~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/cramfs/uncompress.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php