tools/mtd-utils: update to 1.4.5
[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,9 @@
4  #include <stdio.h>
5  #include <stdint.h>
6  #include <string.h>
7 +#ifndef WITHOUT_LZO
8  #include <lzo/lzo1x.h>
9 +#endif
10  #include <linux/types.h>
11  
12  #define crc32 __zlib_crc32
13 @@ -35,7 +37,9 @@
14  #include "ubifs-media.h"
15  #include "mkfs.ubifs.h"
16  
17 +#ifndef WITHOUT_LZO
18  static void *lzo_mem;
19 +#endif
20  static unsigned long long errcnt = 0;
21  static struct ubifs_info *c = &info_;
22  
23 @@ -86,6 +90,7 @@ static int zlib_deflate(void *in_buf, si
24         return 0;
25  }
26  
27 +#ifndef WITHOUT_LZO
28  static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
29                         size_t *out_len)
30  {
31 @@ -103,6 +108,7 @@ static int lzo_compress(void *in_buf, si
32  
33         return 0;
34  }
35 +#endif
36  
37  static int no_compress(void *in_buf, size_t in_len, void *out_buf,
38                        size_t *out_len)
39 @@ -120,14 +126,20 @@ static int favor_lzo_compress(void *in_b
40         int lzo_ret, zlib_ret;
41         size_t lzo_len, zlib_len;
42  
43 +#ifndef WITHOUT_LZO
44         lzo_len = zlib_len = *out_len;
45         lzo_ret = lzo_compress(in_buf, in_len, out_buf, &lzo_len);
46 +#endif
47         zlib_ret = zlib_deflate(in_buf, in_len, zlib_buf, &zlib_len);
48 -
49 +#ifndef WITHOUT_LZO
50         if (lzo_ret && zlib_ret)
51 +#else
52 +       if (zlib_ret)
53 +#endif
54                 /* Both compressors failed */
55                 return -1;
56  
57 +#ifndef WITHOUT_LZO
58         if (!lzo_ret && !zlib_ret) {
59                 double percent;
60  
61 @@ -152,6 +164,7 @@ select_lzo:
62         *out_len = lzo_len;
63         *type = MKFS_UBIFS_COMPR_LZO;
64         return 0;
65 +#endif
66  
67  select_zlib:
68         *out_len = zlib_len;
69 @@ -174,9 +187,11 @@ int compress_data(void *in_buf, size_t i
70                 ret = favor_lzo_compress(in_buf, in_len, out_buf, out_len, &type);
71         else {
72                 switch (type) {
73 +#ifndef WITHOUT_LZO
74                 case MKFS_UBIFS_COMPR_LZO:
75                         ret = lzo_compress(in_buf, in_len, out_buf, out_len);
76                         break;
77 +#endif
78                 case MKFS_UBIFS_COMPR_ZLIB:
79                         ret = zlib_deflate(in_buf, in_len, out_buf, out_len);
80                         break;
81 @@ -198,13 +213,17 @@ int compress_data(void *in_buf, size_t i
82  
83  int init_compression(void)
84  {
85 +#ifndef WITHOUT_LZO
86         lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
87         if (!lzo_mem)
88                 return -1;
89 +#endif
90  
91         zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
92         if (!zlib_buf) {
93 +#ifndef WITHOUT_LZO
94                 free(lzo_mem);
95 +#endif
96                 return -1;
97         }
98  
99 @@ -214,7 +233,9 @@ int init_compression(void)
100  void destroy_compression(void)
101  {
102         free(zlib_buf);
103 +#ifndef WITHOUT_LZO
104         free(lzo_mem);
105 +#endif
106         if (errcnt)
107                 fprintf(stderr, "%llu compression errors occurred\n", errcnt);
108  }
109 --- a/mkfs.ubifs/Makefile
110 +++ b/mkfs.ubifs/Makefile
111 @@ -6,7 +6,13 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
112  
113  TARGETS = mkfs.ubifs
114  
115 -LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
116 +ifeq ($(WITHOUT_LZO), 1)
117 +  CPPFLAGS += -DWITHOUT_LZO
118 +else
119 +  LZOLDLIBS = -llzo2
120 +endif
121 +
122 +LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
123  LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd
124  LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
125