[package] revert r23048 for now until Darwin compile issues have been sorted out...
[openwrt/svn-archive/archive.git] / tools / mtd-utils / patches / 101-ubifs-optional_lzo.patch
1 diff --git a/mkfs.ubifs/Makefile b/mkfs.ubifs/Makefile
2 index a678b0a..919ce89 100644
3 --- a/mkfs.ubifs/Makefile
4 +++ b/mkfs.ubifs/Makefile
5 @@ -5,7 +5,7 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
6
7 TARGETS = mkfs.ubifs
8
9 -LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L../ubi-utils/ -lubi
10 +LDLIBS_mkfs.ubifs = -lz $(if,$(NO_LZO),,-llzo2) -lm -luuid -L../ubi-utils/ -lubi
11
12 include ../common.mk
13
14 diff --git a/mkfs.ubifs/compr.c b/mkfs.ubifs/compr.c
15 index e378c5d..0208f80 100644
16 --- a/mkfs.ubifs/compr.c
17 +++ b/mkfs.ubifs/compr.c
18 @@ -25,7 +25,9 @@
19 #include <stdint.h>
20 #include <string.h>
21 #include <zlib.h>
22 +#if CONFIG_UBIFS_LZO
23 #include <lzo/lzo1x.h>
24 +#endif
25 #include <linux/types.h>
26
27 #include "compr.h"
28 @@ -83,6 +85,17 @@ static int zlib_deflate(void *in_buf, size_t in_len, void *out_buf,
29 return 0;
30 }
31
32 +static int no_compress(void *in_buf, size_t in_len, void *out_buf,
33 + size_t *out_len)
34 +{
35 + memcpy(out_buf, in_buf, in_len);
36 + *out_len = in_len;
37 + return 0;
38 +}
39 +
40 +
41 +#if CONFIG_UBIFS_LZO
42 +
43 static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
44 size_t *out_len)
45 {
46 @@ -101,14 +114,16 @@ static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
47 return 0;
48 }
49
50 -static int no_compress(void *in_buf, size_t in_len, void *out_buf,
51 - size_t *out_len)
52 +#else
53 +
54 +static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
55 + size_t *out_len)
56 {
57 - memcpy(out_buf, in_buf, in_len);
58 - *out_len = in_len;
59 - return 0;
60 + return -1;
61 }
62
63 +#endif
64 +
65 static char *zlib_buf;
66
67 static int favor_lzo_compress(void *in_buf, size_t in_len, void *out_buf,
68 @@ -195,9 +210,11 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
69
70 int init_compression(void)
71 {
72 +#ifdef CONFIG_UBIFS_LZO
73 lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
74 if (!lzo_mem)
75 return -1;
76 +#endif
77
78 zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
79 if (!zlib_buf) {
80 @@ -211,7 +228,9 @@ int init_compression(void)
81 void destroy_compression(void)
82 {
83 free(zlib_buf);
84 +#ifdef CONFIG_UBIFS_LZO
85 free(lzo_mem);
86 +#endif
87 if (errcnt)
88 fprintf(stderr, "%llu compression errors occurred\n", errcnt);
89 }