public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@logfs.org>
To: "Jörn Engel" <joern@logfs.org>
Cc: akpm@osdl.org, Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	linux-fsdevel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	David Woodhouse <dwmw2@infradead.org>
Subject: [Patch 04/18] fs/logfs/compr.c
Date: Wed, 8 Aug 2007 18:15:34 +0200	[thread overview]
Message-ID: <20070808161534.GF15319@lazybastard.org> (raw)
In-Reply-To: <20070808161234.GB15319@lazybastard.org>

--- /dev/null	2007-08-05 21:14:35.622844160 +0200
+++ linux-2.6.21logfs/fs/logfs/compr.c	2007-08-08 02:57:37.000000000 +0200
@@ -0,0 +1,95 @@
+/*
+ * fs/logfs/compr.c	- compression routines
+ *
+ * As should be obvious for Linux kernel code, license is GPLv2
+ *
+ * Copyright (c) 2005-2007 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);
+}

  parent reply	other threads:[~2007-08-08 16:19 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-08 16:12 LogFS take five Jörn Engel
2007-08-08 16:13 ` [Patch 01/18] fs/logfs/Makefile Jörn Engel
2007-08-08 16:14 ` [Patch 02/18] include/linux/logfs.h Jörn Engel
2007-08-08 22:56   ` Arnd Bergmann
2007-08-09 20:03     ` Jörn Engel
2007-08-08 16:15 ` [Patch 03/18] fs/logfs/logfs.h Jörn Engel
2007-08-08 16:15 ` Jörn Engel [this message]
2007-08-08 16:16 ` [Patch 05/18] fs/logfs/dir.c Jörn Engel
2007-08-08 17:07   ` Artem Bityutskiy
2007-08-08 17:15     ` Jörn Engel
2007-08-08 17:34       ` Artem Bityutskiy
2007-08-08 17:41         ` Jörn Engel
2007-08-08 18:50   ` Artem Bityutskiy
2007-08-08 16:17 ` [Patch 05/18] fs/logfs/file.c Jörn Engel
2007-08-08 16:17 ` [Patch 07/18] fs/logfs/gc.c Jörn Engel
2007-08-08 16:18 ` [Patch 08/18] fs/logfs/inode.c Jörn Engel
2007-08-08 16:19 ` [Patch 08/18] fs/logfs/journal.c Jörn Engel
2007-08-08 16:19 ` [Patch 10/18] fs/logfs/memtree.c Jörn Engel
2007-08-08 16:20 ` [Patch 11/18] fs/logfs/readwrite.c Jörn Engel
2007-08-08 16:20 ` [Patch 12/18] fs/logfs/segment.c Jörn Engel
2007-08-08 16:21 ` [Patch 13/18] fs/logfs/super.c Jörn Engel
2007-08-08 16:22 ` [Patch 14/18] fs/logfs/progs/fsck.c Jörn Engel
2007-08-08 16:22 ` [Patch 15/18] fs/logfs/Locking Jörn Engel
2007-08-08 16:23 ` [Patch 16/18] fs/Kconfig Jörn Engel
2007-08-08 23:01   ` Arnd Bergmann
2007-08-09 20:03     ` Jörn Engel
2007-08-08 16:24 ` [Patch 17/18] fs/Makefile Jörn Engel
2007-08-08 16:24 ` [Patch 18/18] include/linux/Kbuild Jörn Engel
2007-08-09  0:19   ` Christoph Hellwig
2007-08-09  2:32     ` Jörn Engel
2007-08-09  2:39       ` Christoph Hellwig
2007-08-09  2:39         ` Jörn Engel
2007-08-09  2:45           ` Christoph Hellwig
2007-08-08 16:27 ` LogFS take five Artem Bityutskiy
2007-08-08 16:35   ` Jörn Engel
2007-08-08 16:52     ` Artem Bityutskiy

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=20070808161534.GF15319@lazybastard.org \
    --to=joern@logfs.org \
    --cc=akpm@osdl.org \
    --cc=arnd@arndb.de \
    --cc=dwmw2@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=tglx@linutronix.de \
    /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