Root/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@@ -35,7 +34,6 @@
12 #include "ubifs-media.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@@ -86,6 +84,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@@ -103,6 +120,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@@ -123,7 +146,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@@ -198,23 +220,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/mkfs.ubifs/Makefile
104+++ b/mkfs.ubifs/Makefile
105@@ -6,7 +6,13 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
106 
107 TARGETS = mkfs.ubifs
108 
109-LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
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 -L$(BUILDDIR)/../ubi-utils/ -lubi
117 LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd
118 LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
119 
120

Archive Download this file



interactive