squashfs-tools-20180628_lzip-0.diff 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. diff -urdN squashfs-tools-master/INSTALL squashfs-tools-master.new/INSTALL
  2. --- squashfs-tools-master/INSTALL 2018-06-12 06:07:02.000000000 +0200
  3. +++ squashfs-tools-master.new/INSTALL 2018-07-10 13:27:23.000000000 +0200
  4. @@ -26,5 +26,5 @@
  5. By default the tools are built with GZIP compression and extended attribute
  6. support. Read the Makefile in squashfs-tools/ for instructions on building
  7. -LZO, LZ4 and XZ compression support, and for instructions on disabling GZIP
  8. -and extended attribute support if desired.
  9. +LZIP, LZO, LZ4 and XZ compression support, and for instructions on disabling
  10. +GZIP and extended attribute support if desired.
  11. diff -urdN squashfs-tools-master/RELEASE-README squashfs-tools-master.new/RELEASE-README
  12. --- squashfs-tools-master/RELEASE-README 2018-06-12 06:07:02.000000000 +0200
  13. +++ squashfs-tools-master.new/RELEASE-README 2018-07-10 13:27:23.000000000 +0200
  14. @@ -8,7 +8,7 @@
  15. for details of changes.
  16. Squashfs is a highly compressed read-only filesystem for Linux.
  17. -It uses either gzip/xz/lzo/lz4 compression to compress both files, inodes
  18. +It uses either gzip/lzip/xz/lzo/lz4 compression to compress both files, inodes
  19. and directories. Inodes in the system are very small and all blocks are
  20. packed to minimise data overhead. Block sizes greater than 4K are supported
  21. up to a maximum of 1Mbytes (default block size 128K).
  22. @@ -39,7 +39,7 @@
  23. 6. File duplicates are detected and removed.
  24. -7. Filesystems can be compressed with gzip, xz (lzma2), lzo or lz4
  25. +7. Filesystems can be compressed with gzip, lzip, xz (lzma2), lzo or lz4
  26. compression algorithms.
  27. 1.1 Extended attributes (xattrs)
  28. @@ -103,6 +103,7 @@
  29. -comp <comp> select <comp> compression
  30. Compressors available:
  31. gzip (default)
  32. + lzip
  33. lzo
  34. lz4
  35. xz
  36. @@ -181,6 +182,15 @@
  37. and choose the best compression.
  38. Available strategies: default, filtered, huffman_only,
  39. run_length_encoded and fixed
  40. + lzip
  41. + -Xcompression-level <compression-level>
  42. + <compression-level> should be 0 .. 9 (default 9)
  43. + -Xdict-size <dict-size>
  44. + Use <dict-size> as the LZIP dictionary size. The dictionary
  45. + size can be specified as a percentage of the block size, or
  46. + as an absolute value. The dictionary size must be less than
  47. + or equal to the block size and 4096 bytes or larger.
  48. + Example dict-sizes are 25%, 37.5% or 8K, 32K, etc.
  49. lzo
  50. -Xalgorithm <algorithm>
  51. Where <algorithm> is one of:
  52. @@ -279,7 +289,7 @@
  53. algorithm. This algorithm offers a good trade-off between compression
  54. ratio, and memory and time taken to decompress.
  55. -Squashfs also supports LZ4, LZO and XZ (LZMA2) compression. LZO offers worse
  56. +Squashfs also supports LZIP, LZ4, LZO and XZ compression. LZO offers worse
  57. compression ratio than gzip, but is faster to decompress. XZ offers better
  58. compression ratio than gzip, but at the expense of greater memory and time
  59. to decompress (and significantly more time to compress). LZ4 is similar
  60. @@ -304,6 +314,15 @@
  61. and choose the best compression.
  62. Available strategies: default, filtered, huffman_only,
  63. run_length_encoded and fixed
  64. + lzip
  65. + -Xcompression-level <compression-level>
  66. + <compression-level> should be 0 .. 9 (default 9)
  67. + -Xdict-size <dict-size>
  68. + Use <dict-size> as the LZIP dictionary size. The dictionary
  69. + size can be specified as a percentage of the block size, or
  70. + as an absolute value. The dictionary size must be less than
  71. + or equal to the block size and 4096 bytes or larger.
  72. + Example dict-sizes are 25%, 37.5% or 8K, 32K, etc.
  73. lzo
  74. -Xalgorithm <algorithm>
  75. Where <algorithm> is one of:
  76. @@ -340,7 +359,7 @@
  77. web sites should be consulted to understand their behaviour. In general
  78. the Mksquashfs compression defaults for each compressor are optimised to
  79. give the best performance for each compressor, where what constitutes
  80. -best depends on the compressor. For gzip/xz best means highest compression,
  81. +best depends on the compressor. For gzip/lzip/xz best means highest compression,
  82. for LZO/LZ4 best means a tradeoff between compression and (de)-compression
  83. overhead (LZO/LZ4 by definition are intended for weaker processors).
  84. @@ -767,6 +786,7 @@
  85. Decompressors available:
  86. gzip
  87. + lzip
  88. lzo
  89. lz4
  90. xz
  91. diff -urdN squashfs-tools-master/squashfs-tools/Makefile squashfs-tools-master.new/squashfs-tools/Makefile
  92. --- squashfs-tools-master/squashfs-tools/Makefile 2018-06-12 06:07:02.000000000 +0200
  93. +++ squashfs-tools-master.new/squashfs-tools/Makefile 2018-07-10 13:27:23.000000000 +0200
  94. @@ -17,6 +17,15 @@
  95. #
  96. GZIP_SUPPORT = 1
  97. +########### Building LZIP support #############
  98. +#
  99. +# The lzlib library (http://www.nongnu.org/lzip/lzlib.html) is supported.
  100. +#
  101. +# To build using lzlib - install the library and uncomment the
  102. +# LZIP_SUPPORT line below.
  103. +#
  104. +LZIP_SUPPORT = 1
  105. +
  106. ########### Building XZ support #############
  107. #
  108. # LZMA2 compression.
  109. @@ -143,6 +152,14 @@
  110. COMPRESSORS += gzip
  111. endif
  112. +ifeq ($(LZIP_SUPPORT),1)
  113. +CFLAGS += -DLZIP_SUPPORT
  114. +MKSQUASHFS_OBJS += lzip_wrapper.o
  115. +UNSQUASHFS_OBJS += lzip_wrapper.o
  116. +LIBS += -llz
  117. +COMPRESSORS += lzip
  118. +endif
  119. +
  120. ifeq ($(LZMA_SUPPORT),1)
  121. LZMA_OBJS = $(LZMA_DIR)/C/Alloc.o $(LZMA_DIR)/C/LzFind.o \
  122. $(LZMA_DIR)/C/LzmaDec.o $(LZMA_DIR)/C/LzmaEnc.o $(LZMA_DIR)/C/LzmaLib.o
  123. @@ -229,8 +246,8 @@
  124. # At least one compressor must have been selected
  125. #
  126. ifndef COMPRESSORS
  127. -$(error "No compressor selected! Select one or more of GZIP, LZMA, XZ, LZO or \
  128. - LZ4!")
  129. +$(error "No compressor selected! Select one or more of GZIP, LZIP, LZMA, XZ, \
  130. + LZO, LZ4 or ZSTD!")
  131. endif
  132. #
  133. @@ -285,6 +302,8 @@
  134. gzip_wrapper.o: gzip_wrapper.c squashfs_fs.h gzip_wrapper.h compressor.h
  135. +lzip_wrapper.o: lzip_wrapper.c squashfs_fs.h lzip_wrapper.h compressor.h
  136. +
  137. lzma_wrapper.o: lzma_wrapper.c compressor.h squashfs_fs.h
  138. lzma_xz_wrapper.o: lzma_xz_wrapper.c compressor.h squashfs_fs.h
  139. diff -urdN squashfs-tools-master/squashfs-tools/compressor.c squashfs-tools-master.new/squashfs-tools/compressor.c
  140. --- squashfs-tools-master/squashfs-tools/compressor.c 2018-06-12 06:07:02.000000000 +0200
  141. +++ squashfs-tools-master.new/squashfs-tools/compressor.c 2018-07-10 13:27:23.000000000 +0200
  142. @@ -33,6 +33,14 @@
  143. extern struct compressor gzip_comp_ops;
  144. #endif
  145. +#ifndef LZIP_SUPPORT
  146. +static struct compressor lzip_comp_ops = {
  147. + LZIP_COMPRESSION, "lzip"
  148. +};
  149. +#else
  150. +extern struct compressor lzip_comp_ops;
  151. +#endif
  152. +
  153. #ifndef LZMA_SUPPORT
  154. static struct compressor lzma_comp_ops = {
  155. LZMA_COMPRESSION, "lzma"
  156. @@ -80,6 +88,7 @@
  157. struct compressor *compressor[] = {
  158. &gzip_comp_ops,
  159. + &lzip_comp_ops,
  160. &lzma_comp_ops,
  161. &lzo_comp_ops,
  162. &lz4_comp_ops,
  163. diff -urdN squashfs-tools-master/squashfs-tools/lzip_wrapper.c squashfs-tools-master.new/squashfs-tools/lzip_wrapper.c
  164. --- squashfs-tools-master/squashfs-tools/lzip_wrapper.c 1970-01-01 01:00:00.000000000 +0100
  165. +++ squashfs-tools-master.new/squashfs-tools/lzip_wrapper.c 2018-07-10 14:57:57.000000000 +0200
  166. @@ -0,0 +1,462 @@
  167. +/*
  168. + * Copyright (c) 2014
  169. + * Phillip Lougher <phillip@squashfs.org.uk>
  170. + * Copyright (C) 2018 Antonio Diaz Diaz
  171. + *
  172. + * This program is free software; you can redistribute it and/or
  173. + * modify it under the terms of the GNU General Public License
  174. + * as published by the Free Software Foundation; either version 2,
  175. + * or (at your option) any later version.
  176. + *
  177. + * This program is distributed in the hope that it will be useful,
  178. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  179. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  180. + * GNU General Public License for more details.
  181. + *
  182. + * You should have received a copy of the GNU General Public License
  183. + * along with this program; if not, write to the Free Software
  184. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  185. + *
  186. + * lzip_wrapper.c
  187. + *
  188. + * Support for LZIP compression using lzlib
  189. + * http://www.nongnu.org/lzip/lzlib.html
  190. + */
  191. +
  192. +#include <limits.h>
  193. +#include <stdint.h>
  194. +#include <stdio.h>
  195. +#include <stdlib.h>
  196. +#include <string.h>
  197. +#include <lzlib.h>
  198. +
  199. +#include "squashfs_fs.h"
  200. +#include "lzip_wrapper.h"
  201. +#include "compressor.h"
  202. +
  203. +static int dictionary_size = 0;
  204. +static float dictionary_percent = 0;
  205. +
  206. +/* default compression level */
  207. +static int compression_level = LZIP_DEFAULT_COMPRESSION_LEVEL;
  208. +
  209. +/* match_len_limit of each compression level */
  210. +const int match_len[] = { 16, 5, 6, 8, 12, 20, 36, 68, 132, 273 };
  211. +
  212. +static inline int isvalid_ds( const int dictionary_size )
  213. +{
  214. + return (dictionary_size >= LZ_min_dictionary_size() &&
  215. + dictionary_size <= LZ_max_dictionary_size());
  216. +}
  217. +
  218. +/*
  219. + * This function is called by the options parsing code in mksquashfs.c
  220. + * to parse any -X compressor option.
  221. + *
  222. + * Two specific options are supported:
  223. + * -Xcompression-level
  224. + * -Xdict-size
  225. + *
  226. + * This function returns:
  227. + * >=0 (number of additional args parsed) on success
  228. + * -1 if the option was unrecognised, or
  229. + * -2 if the option was recognised, but otherwise bad in
  230. + * some way (e.g. invalid parameter)
  231. + *
  232. + * Note: this function sets internal compressor state, but does not
  233. + * pass back the results of the parsing other than success/failure.
  234. + * The lzip_dump_options() function is called later to get the options in
  235. + * a format suitable for writing to the filesystem.
  236. + */
  237. +static int lzip_options(char *argv[], int argc)
  238. +{
  239. + if(strcmp(argv[0], "-Xcompression-level") == 0) {
  240. + if(argc < 2) {
  241. + fprintf(stderr, "lzip: -Xcompression-level missing "
  242. + "compression level\n");
  243. + fprintf(stderr, "lzip: -Xcompression-level it "
  244. + "should be 0 <= n <= 9\n");
  245. + goto failed;
  246. + }
  247. +
  248. + compression_level = atoi(argv[1]);
  249. + if(compression_level < 0 || compression_level > 9) {
  250. + fprintf(stderr, "lzip: -Xcompression-level invalid, it "
  251. + "should be 0 <= n <= 9\n");
  252. + goto failed;
  253. + }
  254. + if(compression_level == 0) {
  255. + dictionary_size = 65535;
  256. + dictionary_percent = 0;
  257. + }
  258. +
  259. + return 1;
  260. + } else if(strcmp(argv[0], "-Xdict-size") == 0) {
  261. + char *b;
  262. + float size;
  263. +
  264. + if(argc < 2) {
  265. + fprintf(stderr, "lzip: -Xdict-size missing dict-size\n");
  266. + goto failed;
  267. + }
  268. +
  269. + size = strtof(argv[1], &b);
  270. + if(*b == '%') {
  271. + if(size <= 0 || size > 100) {
  272. + fprintf(stderr, "lzip: -Xdict-size percentage "
  273. + "should be 0%% < dict-size <= 100%%\n");
  274. + goto failed;
  275. + }
  276. +
  277. + dictionary_size = 0;
  278. + dictionary_percent = size;
  279. + } else {
  280. + if((float) ((int) size) != size) {
  281. + fprintf(stderr, "lzip: -Xdict-size can't be "
  282. + "fractional unless a percentage of the"
  283. + " block size\n");
  284. + goto failed;
  285. + }
  286. +
  287. + dictionary_size = (int) size;
  288. + dictionary_percent = 0;
  289. +
  290. + if(*b == 'k' || *b == 'K')
  291. + dictionary_size *= 1024;
  292. + else if(*b == 'm' || *b == 'M')
  293. + dictionary_size *= 1024 * 1024;
  294. + else if(*b != '\0') {
  295. + fprintf(stderr, "lzip: -Xdict-size invalid "
  296. + "dict-size\n");
  297. + goto failed;
  298. + }
  299. + if(!isvalid_ds(dictionary_size)) {
  300. + fprintf(stderr, "lzip: -Xdict-size invalid, it "
  301. + "should be %d <= n <= %d\n",
  302. + LZ_min_dictionary_size(),
  303. + LZ_max_dictionary_size());
  304. + goto failed;
  305. + }
  306. + }
  307. +
  308. + return 1;
  309. + }
  310. +
  311. + return -1;
  312. +
  313. +failed:
  314. + return -2;
  315. +}
  316. +
  317. +
  318. +/*
  319. + * This function is called after all options have been parsed.
  320. + * It is used to do post-processing on the compressor options using
  321. + * values that were not expected to be known at option parse time.
  322. + *
  323. + * In this case block_size may not be known until after -Xdict-size has
  324. + * been processed (in the case where -b is specified after -Xdict-size)
  325. + *
  326. + * This function returns 0 on successful post processing, or
  327. + * -1 on error
  328. + */
  329. +static int lzip_options_post(int block_size)
  330. +{
  331. + /*
  332. + * if -Xdict-size has been specified use this to compute the datablock
  333. + * dictionary size
  334. + */
  335. + if(dictionary_size || dictionary_percent) {
  336. + if(dictionary_size) {
  337. + if(dictionary_size > block_size) {
  338. + fprintf(stderr, "lzip: -Xdict-size is larger than"
  339. + " block_size\n");
  340. + goto failed;
  341. + }
  342. + } else
  343. + dictionary_size = block_size * dictionary_percent / 100;
  344. +
  345. + if(dictionary_size < 4096) {
  346. + fprintf(stderr, "lzip: -Xdict-size should be 4096 bytes "
  347. + "or larger\n");
  348. + goto failed;
  349. + }
  350. +
  351. + } else
  352. + /* No -Xdict-size specified, use defaults */
  353. + dictionary_size = block_size;
  354. +
  355. + return 0;
  356. +
  357. +failed:
  358. + return -1;
  359. +}
  360. +
  361. +
  362. +/*
  363. + * This function is called by mksquashfs to dump the parsed
  364. + * compressor options in a format suitable for writing to the
  365. + * compressor options field in the filesystem (stored immediately
  366. + * after the superblock).
  367. + *
  368. + * This function returns a pointer to the compression options structure
  369. + * to be stored (and the size), or NULL if there are no compression
  370. + * options
  371. + */
  372. +static void *lzip_dump_options(int block_size, int *size)
  373. +{
  374. + static struct lzip_comp_opts comp_opts;
  375. +
  376. + /*
  377. + * don't store compressor specific options in file system if the
  378. + * default options are being used - no compressor options in the
  379. + * file system means the default options are always assumed
  380. + *
  381. + * Defaults are:
  382. + * compression_level: LZIP_DEFAULT_COMPRESSION_LEVEL
  383. + * metadata dictionary size: SQUASHFS_METADATA_SIZE
  384. + * datablock dictionary size: block_size
  385. + */
  386. + if(dictionary_size == block_size &&
  387. + compression_level == LZIP_DEFAULT_COMPRESSION_LEVEL)
  388. + return NULL;
  389. +
  390. + comp_opts.dictionary_size = dictionary_size;
  391. + comp_opts.compression_level = compression_level;
  392. +
  393. + SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);
  394. +
  395. + *size = sizeof(comp_opts);
  396. + return &comp_opts;
  397. +}
  398. +
  399. +
  400. +/* Check and swap options read from the filesystem. */
  401. +static int lzip_check_options(struct lzip_comp_opts *comp_opts, int size)
  402. +{
  403. + /* check passed comp opts struct is of the correct length */
  404. + if(size != sizeof(struct lzip_comp_opts))
  405. + goto failed;
  406. +
  407. + SQUASHFS_INSWAP_COMP_OPTS(comp_opts);
  408. +
  409. + /* Check comp_opts structure for correctness */
  410. + if(!isvalid_ds(comp_opts->dictionary_size)) {
  411. + fprintf(stderr, "lzip: bad dictionary size in "
  412. + "compression options structure\n");
  413. + goto failed;
  414. + }
  415. +
  416. + if(comp_opts->compression_level > 9) {
  417. + fprintf(stderr, "lzip: bad compression level in "
  418. + "compression options structure\n");
  419. + goto failed;
  420. + }
  421. +
  422. + return 1;
  423. +
  424. +failed:
  425. + fprintf(stderr, "lzip: error reading stored compressor options from "
  426. + "filesystem!\n");
  427. + return 0;
  428. +}
  429. +
  430. +
  431. +/*
  432. + * This function is a helper specifically for the append mode of
  433. + * mksquashfs. Its purpose is to set the internal compressor state
  434. + * to the stored compressor options in the passed compressor options
  435. + * structure.
  436. + *
  437. + * In effect this function sets up the compressor options
  438. + * to the same state they were when the filesystem was originally
  439. + * generated, this is to ensure on appending, the compressor uses
  440. + * the same compression options that were used to generate the
  441. + * original filesystem.
  442. + *
  443. + * Note, even if there are no compressor options, this function is still
  444. + * called with an empty compressor structure (size == 0), to explicitly
  445. + * set the default options, this is to ensure any user supplied
  446. + * -X options on the appending mksquashfs command line are over-ridden
  447. + *
  448. + * This function returns 0 on sucessful extraction of options, and
  449. + * -1 on error
  450. + */
  451. +static int lzip_extract_options(int block_size, void *buffer, int size)
  452. +{
  453. + if(size == 0) {
  454. + /* set defaults */
  455. + dictionary_size = block_size;
  456. + compression_level = LZIP_DEFAULT_COMPRESSION_LEVEL;
  457. + } else {
  458. + struct lzip_comp_opts *comp_opts = buffer;
  459. + if(!lzip_check_options(comp_opts, size))
  460. + return -1;
  461. +
  462. + dictionary_size = comp_opts->dictionary_size;
  463. + compression_level = comp_opts->compression_level;
  464. + }
  465. +
  466. + return 0;
  467. +}
  468. +
  469. +
  470. +static void lzip_display_options(void *buffer, int size)
  471. +{
  472. + struct lzip_comp_opts *comp_opts = buffer;
  473. + if(!lzip_check_options(comp_opts, size))
  474. + return;
  475. +
  476. + printf("\tcompression-level %d\n", comp_opts->compression_level);
  477. + printf("\tDictionary size %d\n", comp_opts->dictionary_size);
  478. +}
  479. +
  480. +
  481. +/*
  482. + * This function is called by mksquashfs to allocate and initialise
  483. + * a lzip_stream struct, before compress() is called.
  484. + *
  485. + * This function returns 0 on success, and
  486. + * -1 on error
  487. + */
  488. +static int lzip_init(void **strm, int block_size, int datablock)
  489. +{
  490. + struct lzip_stream * const stream = malloc(sizeof(struct lzip_stream));
  491. +
  492. + if(!stream)
  493. + return -1;
  494. +
  495. + /* dict == 65535 and match_len == 16 choose fast encoder */
  496. + stream->dictionary_size =
  497. + (datablock || (compression_level == 0 && dictionary_size == 65535)) ?
  498. + dictionary_size : SQUASHFS_METADATA_SIZE;
  499. + stream->match_len_limit = match_len[compression_level];
  500. + *strm = stream;
  501. + return 0;
  502. +}
  503. +
  504. +
  505. +/* Can be called multiple times after each call to lzip_init */
  506. +static int lzip_compress(void *strm, void *dest, void *src, int size,
  507. + int block_size, int *error)
  508. +{
  509. + int ipos = 0, opos = 0;
  510. + struct lzip_stream * const stream = strm;
  511. + struct LZ_Encoder * const encoder =
  512. + LZ_compress_open(stream->dictionary_size,
  513. + stream->match_len_limit, LLONG_MAX);
  514. +
  515. + if(!encoder || LZ_compress_errno(encoder) != LZ_ok) {
  516. + *error = LZ_mem_error;
  517. + goto failed2;
  518. + }
  519. +
  520. + for(;;) {
  521. + int rd = LZ_compress_write(encoder, src + ipos, size - ipos);
  522. + if(rd < 0)
  523. + goto failed;
  524. + ipos += rd;
  525. + if(ipos >= size)
  526. + LZ_compress_finish(encoder);
  527. + rd = LZ_compress_read(encoder, dest + opos, block_size - opos);
  528. + if(rd < 0)
  529. + goto failed;
  530. + opos += rd;
  531. + if(LZ_compress_finished(encoder) == 1)
  532. + break;
  533. + if(opos >= block_size) {
  534. + /* Output buffer overflow. Return out of buffer space */
  535. + opos = 0;
  536. + break;
  537. + }
  538. + }
  539. +
  540. + LZ_compress_close(encoder);
  541. + return opos;
  542. +
  543. +failed:
  544. + /*
  545. + * All other errors return failure, with the compressor
  546. + * specific error code in *error
  547. + */
  548. + *error = LZ_compress_errno(encoder);
  549. +failed2:
  550. + LZ_compress_close(encoder);
  551. + return -1;
  552. +}
  553. +
  554. +
  555. +static int lzip_uncompress(void *dest, void *src, int size, int outsize,
  556. + int *error)
  557. +{
  558. + int ipos = 0, opos = 0;
  559. + struct LZ_Decoder * const decoder = LZ_decompress_open();
  560. +
  561. + if(!decoder || LZ_decompress_errno(decoder) != LZ_ok) {
  562. + *error = LZ_mem_error;
  563. + goto failed2;
  564. + }
  565. +
  566. + for(;;) {
  567. + int rd = LZ_decompress_write(decoder, src + ipos, size - ipos);
  568. + if(rd < 0)
  569. + goto failed;
  570. + ipos += rd;
  571. + if(ipos >= size)
  572. + LZ_decompress_finish(decoder);
  573. + rd = LZ_decompress_read(decoder, dest + opos, outsize - opos);
  574. + if(rd < 0)
  575. + goto failed;
  576. + opos += rd;
  577. + if(LZ_decompress_finished(decoder) == 1)
  578. + break;
  579. + if(opos >= outsize) {
  580. + /* Output buffer overflow. Return out of buffer space */
  581. + *error = LZ_mem_error;
  582. + goto failed2;
  583. + }
  584. + }
  585. +
  586. + LZ_decompress_close(decoder);
  587. + return opos;
  588. +
  589. +failed:
  590. + /*
  591. + * All other errors return failure, with the compressor
  592. + * specific error code in *error
  593. + */
  594. + *error = LZ_decompress_errno(decoder);
  595. +failed2:
  596. + LZ_decompress_close(decoder);
  597. + return -1;
  598. +}
  599. +
  600. +
  601. +static void lzip_usage()
  602. +{
  603. + fprintf(stderr, "\t -Xcompression-level <compression-level>\n"
  604. + "\t\t<compression-level> should be 0 .. 9 (default %d)\n",
  605. + LZIP_DEFAULT_COMPRESSION_LEVEL);
  606. + fprintf(stderr, "\t -Xdict-size <dict-size>\n"
  607. + "\t\tUse <dict-size> as the LZIP dictionary size. The dictionary\n"
  608. + "\t\tsize can be specified as a percentage of the block size, or\n"
  609. + "\t\tas an absolute value. The dictionary size must be less than\n"
  610. + "\t\tor equal to the block size and 4096 bytes or larger.\n"
  611. + "\t\tExample dict-sizes are 25%%, 37.5%% or 8K, 32K, etc.\n");
  612. +}
  613. +
  614. +
  615. +struct compressor lzip_comp_ops = {
  616. + .init = lzip_init,
  617. + .compress = lzip_compress,
  618. + .uncompress = lzip_uncompress,
  619. + .options = lzip_options,
  620. + .options_post = lzip_options_post,
  621. + .dump_options = lzip_dump_options,
  622. + .extract_options = lzip_extract_options,
  623. + .display_options = lzip_display_options,
  624. + .usage = lzip_usage,
  625. + .id = LZIP_COMPRESSION,
  626. + .name = "lzip",
  627. + .supported = 1
  628. +};
  629. diff -urdN squashfs-tools-master/squashfs-tools/lzip_wrapper.h squashfs-tools-master.new/squashfs-tools/lzip_wrapper.h
  630. --- squashfs-tools-master/squashfs-tools/lzip_wrapper.h 1970-01-01 01:00:00.000000000 +0100
  631. +++ squashfs-tools-master.new/squashfs-tools/lzip_wrapper.h 2018-06-10 11:22:39.000000000 +0200
  632. @@ -0,0 +1,58 @@
  633. +#ifndef LZIP_WRAPPER_H
  634. +#define LZIP_WRAPPER_H
  635. +/*
  636. + * Squashfs
  637. + *
  638. + * Copyright (c) 2014
  639. + * Phillip Lougher <phillip@squashfs.org.uk>
  640. + * Copyright (C) 2018 Antonio Diaz Diaz
  641. + *
  642. + * This program is free software; you can redistribute it and/or
  643. + * modify it under the terms of the GNU General Public License
  644. + * as published by the Free Software Foundation; either version 2,
  645. + * or (at your option) any later version.
  646. + *
  647. + * This program is distributed in the hope that it will be useful,
  648. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  649. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  650. + * GNU General Public License for more details.
  651. + *
  652. + * You should have received a copy of the GNU General Public License
  653. + * along with this program; if not, write to the Free Software
  654. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  655. + *
  656. + * lzip_wrapper.h
  657. + *
  658. + */
  659. +
  660. +#ifndef linux
  661. +#define __BYTE_ORDER BYTE_ORDER
  662. +#define __BIG_ENDIAN BIG_ENDIAN
  663. +#define __LITTLE_ENDIAN LITTLE_ENDIAN
  664. +#else
  665. +#include <endian.h>
  666. +#endif
  667. +
  668. +#if __BYTE_ORDER == __BIG_ENDIAN
  669. +extern unsigned int inswap_le32(unsigned int);
  670. +
  671. +#define SQUASHFS_INSWAP_COMP_OPTS(s) { \
  672. + (s)->dictionary_size = inswap_le32((s)->dictionary_size); \
  673. +}
  674. +#else
  675. +#define SQUASHFS_INSWAP_COMP_OPTS(s)
  676. +#endif
  677. +
  678. +/* Default compression */
  679. +#define LZIP_DEFAULT_COMPRESSION_LEVEL 9
  680. +
  681. +struct lzip_comp_opts {
  682. + int32_t dictionary_size;
  683. + uint8_t compression_level;
  684. +};
  685. +
  686. +struct lzip_stream {
  687. + int dictionary_size;
  688. + short match_len_limit;
  689. +};
  690. +#endif
  691. diff -urdN squashfs-tools-master/squashfs-tools/squashfs_fs.h squashfs-tools-master.new/squashfs-tools/squashfs_fs.h
  692. --- squashfs-tools-master/squashfs-tools/squashfs_fs.h 2018-06-12 06:07:02.000000000 +0200
  693. +++ squashfs-tools-master.new/squashfs-tools/squashfs_fs.h 2018-07-10 13:27:23.000000000 +0200
  694. @@ -282,6 +282,7 @@
  695. #define XZ_COMPRESSION 4
  696. #define LZ4_COMPRESSION 5
  697. #define ZSTD_COMPRESSION 6
  698. +#define LZIP_COMPRESSION 7
  699. struct squashfs_super_block {
  700. unsigned int s_magic;