commit cd19d49d66967ef31e4cc7f01550863bc500a132
parent f89b55c039dbf0f804464ed2bdbcc413164af630
Author: sin <sin@2f30.org>
Date: Fri, 8 Mar 2019 12:59:36 +0000
Move compress/decompress functions to compress.c
Diffstat:
5 files changed, 64 insertions(+), 54 deletions(-)
diff --git a/Makefile b/Makefile
@@ -10,7 +10,7 @@ SRC = \
tree.h \
cache.c \
chunker.c \
- config.c \
+ compress.c \
pack.c \
types.c \
unpack.c \
@@ -20,7 +20,7 @@ OBJ = \
$(BIN).o \
cache.o \
chunker.o \
- config.o \
+ compress.o \
pack.o \
types.o \
unpack.o \
diff --git a/compress.c b/compress.c
@@ -0,0 +1,56 @@
+#include <err.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <lz4.h>
+
+int compr_enabled = 1;
+
+size_t
+compr_size(size_t size)
+{
+ size_t ret;
+
+ if (compr_enabled)
+ ret = LZ4_compressBound(size);
+ else
+ ret = size;
+
+ return ret;
+}
+
+size_t
+compr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize)
+{
+ int ret;
+
+ if (compr_enabled) {
+ ret = LZ4_compress_default((char *)in, (char *)out, insize,
+ outsize);
+ if (ret < 0)
+ errx(1, "LZ4_compress_default failed");
+ } else {
+ ret = insize;
+ memcpy(out, in, insize);
+ }
+
+ return ret;
+}
+
+size_t
+decompr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize)
+{
+ int ret;
+
+ if (compr_enabled) {
+ ret = LZ4_decompress_safe((char *)in, (char *)out, insize,
+ outsize);
+ if (ret < 0)
+ errx(1, "LZ4_decompress_safe failed");
+ } else {
+ ret = insize;
+ memcpy(out, in, insize);
+ }
+
+ return ret;
+}
diff --git a/config.c b/config.c
@@ -1 +0,0 @@
-int compr_enabled = 1;
diff --git a/dedup.c b/dedup.c
@@ -10,7 +10,6 @@
#include <string.h>
#include <unistd.h>
-#include <lz4.h>
#include <openssl/sha.h>
#include "arg.h"
@@ -41,55 +40,6 @@ static unsigned long long cache_misses;
int verbose;
char *argv0;
-static size_t
-compr_size(size_t size)
-{
- size_t ret;
-
- if (compr_enabled)
- ret = LZ4_compressBound(size);
- else
- ret = size;
-
- return ret;
-}
-
-static size_t
-compr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize)
-{
- int ret;
-
- if (compr_enabled) {
- ret = LZ4_compress_default((char *)in, (char *)out, insize,
- outsize);
- if (ret < 0)
- errx(1, "LZ4_compress_default failed");
- } else {
- ret = insize;
- memcpy(out, in, insize);
- }
-
- return ret;
-}
-
-static size_t
-decompr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize)
-{
- int ret;
-
- if (compr_enabled) {
- ret = LZ4_decompress_safe((char *)in, (char *)out, insize,
- outsize);
- if (ret < 0)
- errx(1, "LZ4_decompress_safe failed");
- } else {
- ret = insize;
- memcpy(out, in, insize);
- }
-
- return ret;
-}
-
static void
print_md(FILE *fp, uint8_t *md, size_t size)
{
diff --git a/dedup.h b/dedup.h
@@ -64,7 +64,7 @@ struct snapshot {
struct blk_desc blk_desc[];
};
-/* config.c */
+/* compress.c */
extern int compr_enabled;
/* dedup.c */
@@ -85,6 +85,11 @@ ssize_t fill_chunker(struct chunker *chunker);
uint8_t *get_chunk(struct chunker *chunker, size_t *chunk_size);
void drain_chunker(struct chunker *chunker);
+/* compress.c */
+size_t compr_size(size_t size);
+size_t compr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize);
+size_t decompr(uint8_t *in, uint8_t *out, size_t insize, size_t outsize);
+
/* pack.c */
int pack(unsigned char *dst, char *fmt, ...);