tools/mtd-utils: update to version git-20100912
[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 @@ -6,7 +6,7 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
6
7 TARGETS = mkfs.ubifs
8
9 -LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
10 +LDLIBS_mkfs.ubifs = -lz $(if,$(NO_LZO),,-llzo2) -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
11 LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd -lcrc32
12 LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
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 @@ -24,7 +24,9 @@
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <string.h>
22 +#if CONFIG_UBIFS_LZO
23 #include <lzo/lzo1x.h>
24 +#endif
25 #include <linux/types.h>
26
27 #define crc32 __zlib_crc32
28 @@ -85,6 +87,16 @@ static int zlib_deflate(void *in_buf, si
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 +#if CONFIG_UBIFS_LZO
41 +
42 static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
43 size_t *out_len)
44 {
45 @@ -103,14 +115,16 @@ static int lzo_compress(void *in_buf, si
46 return 0;
47 }
48
49 -static int no_compress(void *in_buf, size_t in_len, void *out_buf,
50 - size_t *out_len)
51 +#else
52 +
53 +static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
54 + size_t *out_len)
55 {
56 - memcpy(out_buf, in_buf, in_len);
57 - *out_len = in_len;
58 - return 0;
59 + return 1;
60 }
61
62 +#endif
63 +
64 static char *zlib_buf;
65
66 static int favor_lzo_compress(void *in_buf, size_t in_len, void *out_buf,
67 @@ -197,9 +211,11 @@ int compress_data(void *in_buf, size_t i
68
69 int init_compression(void)
70 {
71 +#ifdef CONFIG_UBIFS_LZO
72 lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
73 if (!lzo_mem)
74 return -1;
75 +#endif
76
77 zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
78 if (!zlib_buf) {
79 @@ -213,7 +229,9 @@ int init_compression(void)
80 void destroy_compression(void)
81 {
82 free(zlib_buf);
83 +#ifdef CONFIG_UBIFS_LZO
84 free(lzo_mem);
85 +#endif
86 if (errcnt)
87 fprintf(stderr, "%llu compression errors occurred\n", errcnt);
88 }