135-mkubifs_optional_lzo.patch 2.5 KB

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