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

TOMOYO Linux Cross Reference
Linux/fs/jffs2/compr_lzo.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.11 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.84 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.154 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.201 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.201 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.77 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * JFFS2 -- Journalling Flash File System, Version 2.
  3  *
  4  * Copyright © 2007 Nokia Corporation. All rights reserved.
  5  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
  6  *
  7  * Created by Richard Purdie <rpurdie@openedhand.com>
  8  *
  9  * For licensing information, see the file 'LICENCE' in this directory.
 10  *
 11  */
 12 
 13 #include <linux/kernel.h>
 14 #include <linux/sched.h>
 15 #include <linux/vmalloc.h>
 16 #include <linux/init.h>
 17 #include <linux/lzo.h>
 18 #include "compr.h"
 19 
 20 static void *lzo_mem;
 21 static void *lzo_compress_buf;
 22 static DEFINE_MUTEX(deflate_mutex);     /* for lzo_mem and lzo_compress_buf */
 23 
 24 static void free_workspace(void)
 25 {
 26         vfree(lzo_mem);
 27         vfree(lzo_compress_buf);
 28 }
 29 
 30 static int __init alloc_workspace(void)
 31 {
 32         lzo_mem = vmalloc(LZO1X_MEM_COMPRESS);
 33         lzo_compress_buf = vmalloc(lzo1x_worst_compress(PAGE_SIZE));
 34 
 35         if (!lzo_mem || !lzo_compress_buf) {
 36                 printk(KERN_WARNING "Failed to allocate lzo deflate workspace\n");
 37                 free_workspace();
 38                 return -ENOMEM;
 39         }
 40 
 41         return 0;
 42 }
 43 
 44 static int jffs2_lzo_compress(unsigned char *data_in, unsigned char *cpage_out,
 45                               uint32_t *sourcelen, uint32_t *dstlen)
 46 {
 47         size_t compress_size;
 48         int ret;
 49 
 50         mutex_lock(&deflate_mutex);
 51         ret = lzo1x_1_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem);
 52         if (ret != LZO_E_OK)
 53                 goto fail;
 54 
 55         if (compress_size > *dstlen)
 56                 goto fail;
 57 
 58         memcpy(cpage_out, lzo_compress_buf, compress_size);
 59         mutex_unlock(&deflate_mutex);
 60 
 61         *dstlen = compress_size;
 62         return 0;
 63 
 64  fail:
 65         mutex_unlock(&deflate_mutex);
 66         return -1;
 67 }
 68 
 69 static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out,
 70                                  uint32_t srclen, uint32_t destlen)
 71 {
 72         size_t dl = destlen;
 73         int ret;
 74 
 75         ret = lzo1x_decompress_safe(data_in, srclen, cpage_out, &dl);
 76 
 77         if (ret != LZO_E_OK || dl != destlen)
 78                 return -1;
 79 
 80         return 0;
 81 }
 82 
 83 static struct jffs2_compressor jffs2_lzo_comp = {
 84         .priority = JFFS2_LZO_PRIORITY,
 85         .name = "lzo",
 86         .compr = JFFS2_COMPR_LZO,
 87         .compress = &jffs2_lzo_compress,
 88         .decompress = &jffs2_lzo_decompress,
 89         .disabled = 0,
 90 };
 91 
 92 int __init jffs2_lzo_init(void)
 93 {
 94         int ret;
 95 
 96         ret = alloc_workspace();
 97         if (ret < 0)
 98                 return ret;
 99 
100         ret = jffs2_register_compressor(&jffs2_lzo_comp);
101         if (ret)
102                 free_workspace();
103 
104         return ret;
105 }
106 
107 void jffs2_lzo_exit(void)
108 {
109         jffs2_unregister_compressor(&jffs2_lzo_comp);
110         free_workspace();
111 }
112 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp