tools/mtd-utils: Mark some lzma functions as static
[openwrt/openwrt.git] / tools / mtd-utils / patches / 135-mkubifs_optional_lzo.patch
1 --- a/mkfs.ubifs/compr.c
2 +++ b/mkfs.ubifs/compr.c
3 @@ -24,7 +24,6 @@
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <string.h>
7 -#include <lzo/lzo1x.h>
8 #include <linux/types.h>
9
10 #define crc32 __zlib_crc32
11 @@ -34,7 +33,6 @@
12 #include "compr.h"
13 #include "mkfs.ubifs.h"
14
15 -static void *lzo_mem;
16 static unsigned long long errcnt = 0;
17 static struct ubifs_info *c = &info_;
18
19 @@ -85,6 +83,25 @@ static int zlib_deflate(void *in_buf, si
20 return 0;
21 }
22
23 +#ifndef WITHOUT_LZO
24 +#include <lzo/lzo1x.h>
25 +
26 +static void *lzo_mem;
27 +
28 +static int lzo_init(void)
29 +{
30 + lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
31 + if (!lzo_mem)
32 + return -1;
33 +
34 + return 0;
35 +}
36 +
37 +static void lzo_fini(void)
38 +{
39 + free(lzo_mem);
40 +}
41 +
42 static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
43 size_t *out_len)
44 {
45 @@ -102,6 +119,12 @@ static int lzo_compress(void *in_buf, si
46
47 return 0;
48 }
49 +#else
50 +static inline int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
51 + size_t *out_len) { return -1; }
52 +static inline int lzo_init(void) { return 0; }
53 +static inline void lzo_fini(void) { }
54 +#endif
55
56 static int no_compress(void *in_buf, size_t in_len, void *out_buf,
57 size_t *out_len)
58 @@ -122,7 +145,6 @@ static int favor_lzo_compress(void *in_b
59 lzo_len = zlib_len = *out_len;
60 lzo_ret = lzo_compress(in_buf, in_len, out_buf, &lzo_len);
61 zlib_ret = zlib_deflate(in_buf, in_len, zlib_buf, &zlib_len);
62 -
63 if (lzo_ret && zlib_ret)
64 /* Both compressors failed */
65 return -1;
66 @@ -197,23 +219,28 @@ int compress_data(void *in_buf, size_t i
67
68 int init_compression(void)
69 {
70 - lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
71 - if (!lzo_mem)
72 - return -1;
73 + int ret;
74 +
75 + ret = lzo_init();
76 + if (ret)
77 + goto err;
78
79 zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
80 - if (!zlib_buf) {
81 - free(lzo_mem);
82 - return -1;
83 - }
84 + if (!zlib_buf)
85 + goto err_lzo;
86
87 return 0;
88 +
89 +err_lzo:
90 + lzo_fini();
91 +err:
92 + return ret;
93 }
94
95 void destroy_compression(void)
96 {
97 free(zlib_buf);
98 - free(lzo_mem);
99 + lzo_fini();
100 if (errcnt)
101 fprintf(stderr, "%llu compression errors occurred\n", errcnt);
102 }
103 --- a/Makefile
104 +++ b/Makefile
105 @@ -108,7 +108,13 @@ $(call _mkdep,lib/,libmtd.a)
106 obj-mkfs.ubifs = crc16.o lpt.o compr.o devtable.o \
107 hashtable/hashtable.o hashtable/hashtable_itr.o
108 LDFLAGS_mkfs.ubifs = $(ZLIBLDFLAGS) $(LZOLDFLAGS) $(UUIDLDFLAGS)
109 -LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid
110 +ifeq ($(WITHOUT_LZO), 1)
111 + CPPFLAGS += -DWITHOUT_LZO
112 +else
113 + LZOLDLIBS = -llzo2
114 +endif
115 +
116 +LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) -lm -luuid
117 $(call mkdep,mkfs.ubifs/,mkfs.ubifs,,ubi-utils/libubi.a)
118
119 #