login
Header Space

 
 

[Patch 06/18] fs/logfs/compr.c

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-fsdevel@...>, <linux-kernel@...>, <linux-mtd@...>
Cc: <akpm@...>, Sam Ravnborg <sam@...>, John Stoffel <john@...>, David Woodhouse <dwmw2@...>, Jamie Lokier <jamie@...>, Artem Bityutskiy <dedekind@...>, CaT <cat@...>, Jan Engelhardt <jengelh@...>, Evgeniy Polyakov <johnpol@...>, David Weinehall <tao@...>, Arnd Bergmann <arnd@...>, Willy Tarreau <w@...>, Kyle Moffett <mrmacman_g4@...>, Dongjun Shin <djshin90@...>, Pavel Machek <pavel@...>, Bill Davidsen <davidsen@...>, Thomas Gleixner <tglx@...>, Albert Cahalan <acahalan@...>, Pekka Enberg <penberg@...>, Roland Dreier <rdreier@...>, Ondrej Zajicek <santiago@...>, Ulisses Furquim <ulissesf@...>
Date: Sunday, June 3, 2007 - 2:43 pm

--- /dev/null	2007-03-13 19:15:28.862769062 +0100
+++ linux-2.6.21logfs/fs/logfs/compr.c	2007-06-03 19:18:57.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
+ */
+#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 __exit logfs_compr_exit(void)
+{
+	vfree(stream.workspace);
+}
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
LogFS take four, Jörn, (Sun Jun 3, 2:38 pm)
Re: LogFS take four, Evgeniy Polyakov, (Fri Jun 15, 4:37 am)
Re: LogFS take four, Jörn, (Fri Jun 15, 7:10 am)
Re: LogFS take four, Arnd Bergmann, (Sun Jun 3, 6:18 pm)
Re: LogFS take four, Jörn, (Mon Jun 4, 5:05 am)
Re: LogFS take four, Jan-Benedict Glaw, (Sun Jun 3, 3:17 pm)
Re: LogFS take four, Jörn, (Sun Jun 3, 3:19 pm)
[Patch 18/18] fs/logfs/Locking, Jörn, (Sun Jun 3, 2:51 pm)
[Patch 17/18] fs/logfs/progs/mkfs.c, Jörn, (Sun Jun 3, 2:50 pm)
[Patch 16/18] fs/logfs/progs/fsck.c, Jörn, (Sun Jun 3, 2:50 pm)
[Patch 15/18] fs/logfs/super.c, Jörn, (Sun Jun 3, 2:49 pm)
Re: [Patch 15/18] fs/logfs/super.c, Arnd Bergmann, (Sun Jun 10, 12:27 pm)
Re: [Patch 15/18] fs/logfs/super.c, Jörn, (Sun Jun 10, 1:38 pm)
Re: [Patch 15/18] fs/logfs/super.c, Arnd Bergmann, (Sun Jun 10, 2:33 pm)
Re: [Patch 15/18] fs/logfs/super.c, Jörn, (Sun Jun 10, 3:10 pm)
Re: [Patch 15/18] fs/logfs/super.c, Willy Tarreau, (Sun Jun 10, 3:20 pm)
[Patch 14/18] fs/logfs/segment.c, Jörn, (Sun Jun 3, 2:48 pm)
Re: [Patch 14/18] fs/logfs/segment.c, Arnd Bergmann, (Sun Jun 3, 6:21 pm)
Re: [Patch 14/18] fs/logfs/segment.c, Jörn, (Mon Jun 4, 5:07 am)
[Patch 13/18] fs/logfs/readwrite.c, Jörn, (Sun Jun 3, 2:48 pm)
[Patch 12/18] fs/logfs/memtree.c, Jörn, (Sun Jun 3, 2:47 pm)
[Patch 11/18] fs/logfs/journal.c, Jörn, (Sun Jun 3, 2:47 pm)
[Patch 10/18] fs/logfs/inode.c, Jörn, (Sun Jun 3, 2:46 pm)
Re: [Patch 10/18] fs/logfs/inode.c, Arnd Bergmann, (Sun Jun 10, 1:24 pm)
Re: [Patch 10/18] fs/logfs/inode.c, Jörn, (Mon Jun 11, 7:28 pm)
Re: [Patch 10/18] fs/logfs/inode.c, Arnd Bergmann, (Mon Jun 11, 7:51 pm)
Re: [Patch 10/18] fs/logfs/inode.c, Jörn, (Mon Jun 11, 7:57 pm)
Re: [Patch 10/18] fs/logfs/inode.c, Jörn, (Sun Jun 10, 1:40 pm)
[Patch 09/18] fs/logfs/gc.c, Jörn, (Sun Jun 3, 2:46 pm)
Re: [Patch 09/18] fs/logfs/gc.c, Evgeniy Polyakov, (Fri Jun 15, 5:03 am)
Re: [Patch 09/18] fs/logfs/gc.c, Jörn, (Fri Jun 15, 7:14 am)
Re: [Patch 09/18] fs/logfs/gc.c, Evgeniy Polyakov, (Fri Jun 15, 9:03 am)
Re: [Patch 09/18] fs/logfs/gc.c, Arnd Bergmann, (Sun Jun 3, 6:07 pm)
Re: [Patch 09/18] fs/logfs/gc.c, Jörn, (Mon Jun 4, 5:01 am)
[Patch 08/18] fs/logfs/file.c, Jörn, (Sun Jun 3, 2:45 pm)
[Patch 07/18] fs/logfs/dir.c, Jörn, (Sun Jun 3, 2:44 pm)
Re: [Patch 07/18] fs/logfs/dir.c, Evgeniy Polyakov, (Fri Jun 15, 4:59 am)
Re: [Patch 07/18] fs/logfs/dir.c, Jörn, (Fri Jun 15, 7:57 am)
[Patch 06/18] fs/logfs/compr.c, Jörn, (Sun Jun 3, 2:43 pm)
Re: [Patch 06/18] fs/logfs/compr.c, Arnd Bergmann, (Sun Jun 3, 5:58 pm)
Re: [Patch 06/18] fs/logfs/compr.c, Jörn, (Mon Jun 4, 4:54 am)
Re: [Patch 06/18] fs/logfs/compr.c, David Woodhouse, (Mon Jun 4, 9:53 am)
[Patch 05/18] fs/logfs/logfs.h, Jörn, (Sun Jun 3, 2:43 pm)
Re: [Patch 05/18] fs/logfs/logfs.h, Paulo Marques, (Wed Jun 6, 7:29 am)
Re: [Patch 05/18] fs/logfs/logfs.h, Jörn, (Wed Jun 6, 7:29 am)
Re: [Patch 05/18] fs/logfs/logfs.h, Arnd Bergmann, (Sun Jun 3, 5:50 pm)
Re: [Patch 05/18] fs/logfs/logfs.h, Jan Engelhardt, (Mon Jun 4, 4:17 am)
Re: [Patch 05/18] fs/logfs/logfs.h, Jörn, (Mon Jun 4, 5:11 am)
[Patch 04/18] include/linux/logfs.h, Jörn, (Sun Jun 3, 2:42 pm)
Re: [Patch 04/18] include/linux/logfs.h, Arnd Bergmann, (Sun Jun 3, 5:42 pm)
Re: [Patch 04/18] include/linux/logfs.h, Jörn, (Mon Jun 4, 5:12 am)
Re: [Patch 04/18] include/linux/logfs.h, David Woodhouse, (Mon Jun 4, 9:38 am)
Re: [Patch 04/18] include/linux/logfs.h, Segher Boessenkool, (Tue Jun 5, 11:49 am)
Re: [Patch 04/18] include/linux/logfs.h, Bill Davidsen, (Tue Jun 5, 4:39 pm)
Re: [Patch 04/18] include/linux/logfs.h, David Woodhouse, (Tue Jun 5, 11:53 am)
Re: [Patch 04/18] include/linux/logfs.h, Segher Boessenkool, (Tue Jun 5, 2:49 pm)
Re: [Patch 04/18] include/linux/logfs.h, David Woodhouse, (Wed Jun 6, 4:50 am)
Re: [Patch 04/18] include/linux/logfs.h, Arnd Bergmann, (Wed Jun 6, 8:42 am)
Re: [Patch 04/18] include/linux/logfs.h, Andreas Schwab, (Wed Jun 6, 4:59 am)
Re: [Patch 04/18] include/linux/logfs.h, Jörn, (Mon Jun 4, 10:02 am)
[Patch 03/18] fs/logfs/Makefile, Jörn, (Sun Jun 3, 2:41 pm)
[Patch 02/18] fs/Makefile, Jörn, (Sun Jun 3, 2:40 pm)
[Patch 01/18] fs/Kconfig, Jörn, (Sun Jun 3, 2:40 pm)
speck-geostationary