From: Joern Engel <joern@logfs.org>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mtd@lists.infradead.org
Subject: [PATCH 2/17] [LogFS] compr.c
Date: Fri, 20 Nov 2009 20:37:17 +0100 [thread overview]
Message-ID: <E1NBZID-0003fS-OP@longford.logfs.org> (raw)
In-Reply-To: 20091120181113.GA2159@logfs.org
---
fs/logfs/compr.c | 95 ++
diff --git a/fs/logfs/compr.c b/fs/logfs/compr.c
new file mode 100644
index 0000000..44bbfd2
--- /dev/null
+++ b/fs/logfs/compr.c
@@ -0,0 +1,95 @@
+/*
+ * fs/logfs/compr.c - compression routines
+ *
+ * As should be obvious for Linux kernel code, license is GPLv2
+ *
+ * Copyright (c) 2005-2008 Joern Engel <joern@logfs.org>
+ */
+#include "logfs.h"
+#include <linux/vmalloc.h>
+#include <linux/zlib.h>
+
+#define COMPR_LEVEL 3
+
+static DEFINE_MUTEX(compr_mutex);
+static struct z_stream_s stream;
+
+int logfs_compress(void *in, void *out, size_t inlen, size_t outlen)
+{
+ int err, ret;
+
+ ret = -EIO;
+ mutex_lock(&compr_mutex);
+ err = zlib_deflateInit(&stream, COMPR_LEVEL);
+ if (err != Z_OK)
+ goto error;
+
+ stream.next_in = in;
+ stream.avail_in = inlen;
+ stream.total_in = 0;
+ stream.next_out = out;
+ stream.avail_out = outlen;
+ stream.total_out = 0;
+
+ err = zlib_deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END)
+ goto error;
+
+ err = zlib_deflateEnd(&stream);
+ if (err != Z_OK)
+ goto error;
+
+ if (stream.total_out >= stream.total_in)
+ goto error;
+
+ ret = stream.total_out;
+error:
+ mutex_unlock(&compr_mutex);
+ return ret;
+}
+
+int logfs_uncompress(void *in, void *out, size_t inlen, size_t outlen)
+{
+ int err, ret;
+
+ ret = -EIO;
+ mutex_lock(&compr_mutex);
+ err = zlib_inflateInit(&stream);
+ if (err != Z_OK)
+ goto error;
+
+ stream.next_in = in;
+ stream.avail_in = inlen;
+ stream.total_in = 0;
+ stream.next_out = out;
+ stream.avail_out = outlen;
+ stream.total_out = 0;
+
+ err = zlib_inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END)
+ goto error;
+
+ err = zlib_inflateEnd(&stream);
+ if (err != Z_OK)
+ goto error;
+
+ ret = 0;
+error:
+ mutex_unlock(&compr_mutex);
+ return ret;
+}
+
+int __init logfs_compr_init(void)
+{
+ size_t size = max(zlib_deflate_workspacesize(),
+ zlib_inflate_workspacesize());
+ stream.workspace = vmalloc(size);
+ if (!stream.workspace)
+ return -ENOMEM;
+ return 0;
+}
+
+void logfs_compr_exit(void)
+{
+ vfree(stream.workspace);
+}
next prev parent reply other threads:[~2009-11-20 19:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-20 19:37 [PATCH 0/17] [LogFS] New flash filesystem Joern Engel
2009-11-20 19:37 ` [PATCH 1/17] [LogFS] Documentation Joern Engel
2009-11-20 19:37 ` Joern Engel [this message]
2009-11-20 19:37 ` [PATCH 3/17] [LogFS] dev_bdev.c Joern Engel
2009-11-20 19:37 ` [PATCH 4/17] [LogFS] dev_mtd.c Joern Engel
2009-11-20 19:37 ` [PATCH 5/17] [LogFS] dir.c Joern Engel
2009-11-23 11:17 ` Dan Carpenter
2009-11-23 13:32 ` Jörn Engel
2009-11-20 19:37 ` [PATCH 6/17] [LogFS] file.c Joern Engel
2009-11-20 19:37 ` [PATCH 7/17] [LogFS] gc.c Joern Engel
2009-11-20 19:37 ` [PATCH 8/17] [LogFS] inode.c Joern Engel
2009-11-20 19:37 ` [PATCH 9/17] [LogFS] journal.c Joern Engel
2009-11-20 19:37 ` [PATCH 10/17] [LogFS] logfs.h Joern Engel
2009-11-20 19:38 ` [PATCH 11/17] [LogFS] logfs_abi.h Joern Engel
2009-11-20 19:38 ` [PATCH 12/17] [LogFS] readwrite.c Joern Engel
2009-11-23 12:33 ` Pekka Enberg
2009-11-23 13:15 ` Jörn Engel
2009-11-20 19:38 ` [PATCH 13/17] [LogFS] segment.c Joern Engel
2009-11-20 19:38 ` [PATCH 14/17] [LogFS] super.c Joern Engel
2009-11-20 19:38 ` [PATCH 15/17] [LogFS] btree headers Joern Engel
2009-11-20 19:38 ` [PATCH 16/17] [LogFS] btree.c Joern Engel
2009-11-20 19:38 ` [PATCH 17/17] [LogFS] Kconfig and Makefile Joern Engel
2009-11-20 19:38 ` [PATCH 18/17] [LogFS] fio support Joern Engel
2009-11-23 12:18 ` [PATCH 0/17] [LogFS] New flash filesystem Arnd Bergmann
2009-11-25 15:55 ` Jörn Engel
2009-11-25 23:51 ` Stephen Rothwell
2009-11-26 8:36 ` Jörn Engel
2009-11-27 4:24 ` Stephen Rothwell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1NBZID-0003fS-OP@longford.logfs.org \
--to=joern@logfs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).