35a7cd86f5aeef08d0fb840bafef7610bca41287
[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 @@ -83,6 +83,17 @@ static int zlib_deflate(void *in_buf, size_t in_len, void *out_buf,
19 return 0;
20 }
21
22 +static int no_compress(void *in_buf, size_t in_len, void *out_buf,
23 + size_t *out_len)
24 +{
25 + memcpy(out_buf, in_buf, in_len);
26 + *out_len = in_len;
27 + return 0;
28 +}
29 +
30 +
31 +#if CONFIG_UBIFS_LZO
32 +
33 static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
34 size_t *out_len)
35 {
36 @@ -101,14 +112,16 @@ static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
37 return 0;
38 }
39
40 -static int no_compress(void *in_buf, size_t in_len, void *out_buf,
41 - size_t *out_len)
42 +#else
43 +
44 +static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
45 + size_t *out_len)
46 {
47 - memcpy(out_buf, in_buf, in_len);
48 - *out_len = in_len;
49 - return 0;
50 + return -1;
51 }
52
53 +#endif
54 +
55 static char *zlib_buf;
56
57 static int favor_lzo_compress(void *in_buf, size_t in_len, void *out_buf,
58 @@ -195,9 +208,11 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
59
60 int init_compression(void)
61 {
62 +#ifdef CONFIG_UBIFS_LZO
63 lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
64 if (!lzo_mem)
65 return -1;
66 +#endif
67
68 zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
69 if (!zlib_buf) {
70 @@ -211,7 +226,9 @@ int init_compression(void)
71 void destroy_compression(void)
72 {
73 free(zlib_buf);
74 +#ifdef CONFIG_UBIFS_LZO
75 free(lzo_mem);
76 +#endif
77 if (errcnt)
78 fprintf(stderr, "%llu compression errors occurred\n", errcnt);
79 }