2 +++ b/squashfs-tools/lzma_xz_options.h
4 +#ifndef LZMA_XZ_OPTIONS_H
5 +#define LZMA_XZ_OPTIONS_H
8 + * Jonas Gorski <jonas.gorski@gmail.com>
10 + * This program is free software; you can redistribute it and/or
11 + * modify it under the terms of the GNU General Public License
12 + * as published by the Free Software Foundation; either version 2,
13 + * or (at your option) any later version.
15 + * This program is distributed in the hope that it will be useful,
16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 + * GNU General Public License for more details.
20 + * You should have received a copy of the GNU General Public License
21 + * along with this program; if not, write to the Free Software
22 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 +#include <machine/endian.h>
33 +#define __BYTE_ORDER BYTE_ORDER
34 +#define __BIG_ENDIAN BIG_ENDIAN
35 +#define __LITTLE_ENDIAN LITTLE_ENDIAN
44 +#define LZMA_OPT_FLT_MASK 0xffff
45 +#define LZMA_OPT_PRE_OFF 16
46 +#define LZMA_OPT_PRE_MASK (0xf << LZMA_OPT_PRE_OFF)
47 +#define LZMA_OPT_EXTREME 20
49 +#define LZMA_OPT_LC_OFF 0
50 +#define LZMA_OPT_LC_MASK (0x7 << LZMA_OPT_LC_OFF)
51 +#define LZMA_OPT_LP_OFF 3
52 +#define LZMA_OPT_LP_MASK (0x7 << LZMA_OPT_LP_OFF)
53 +#define LZMA_OPT_PB_OFF 6
54 +#define LZMA_OPT_PB_MASK (0x7 << LZMA_OPT_PB_OFF)
59 +#if __BYTE_ORDER == __BIG_ENDIAN
60 +extern unsigned int inswap_le32(unsigned int);
62 +#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s) { \
63 + (s)->flags = inswap_le32((s)->flags); \
64 + (s)->bit_opts = inswap_le16((s)->bit_opts); \
65 + (s)->fb = inswap_le16((s)->fb); \
66 + (s)->dict_size = inswap_le32((s)->dict_size); \
69 +#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s)
72 +#define MEMLIMIT (32 * 1024 * 1024)
74 +#define LZMA_OPT_LC_MIN 0
75 +#define LZMA_OPT_LC_MAX 4
76 +#define LZMA_OPT_LC_DEFAULT 3
78 +#define LZMA_OPT_LP_MIN 0
79 +#define LZMA_OPT_LP_MAX 4
80 +#define LZMA_OPT_LP_DEFAULT 0
82 +#define LZMA_OPT_PB_MIN 0
83 +#define LZMA_OPT_PB_MAX 4
84 +#define LZMA_OPT_PB_DEFAULT 2
86 +#define LZMA_OPT_FB_MIN 5
87 +#define LZMA_OPT_FB_MAX 273
88 +#define LZMA_OPT_FB_DEFAULT 64
95 +struct lzma_xz_options {
106 +struct lzma_xz_options *lzma_xz_get_options(void);
108 +int lzma_xz_options(char *argv[], int argc, int lzmaver);
110 +int lzma_xz_options_post(int block_size, int lzmaver);
112 +void *lzma_xz_dump_options(int block_size, int *size, int flags);
114 +int lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver);
116 +void lzma_xz_usage(int lzmaver);
120 +++ b/squashfs-tools/lzma_xz_options.c
123 + * Copyright (c) 2011
124 + * Jonas Gorski <jonas.gorski@gmail.com>
126 + * This program is free software; you can redistribute it and/or
127 + * modify it under the terms of the GNU General Public License
128 + * as published by the Free Software Foundation; either version 2,
129 + * or (at your option) any later version.
131 + * This program is distributed in the hope that it will be useful,
132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
134 + * GNU General Public License for more details.
136 + * You should have received a copy of the GNU General Public License
137 + * along with this program; if not, write to the Free Software
138 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
142 + * Common options for LZMA1 and 2 compressors. Based on xz_wrapper.c
151 +#include "lzma_xz_options.h"
153 +static const char const *lzmaver_str[] = { "", "lzma", "xz" };
155 +static struct lzma_xz_options options = {
159 + .lc = LZMA_OPT_LC_DEFAULT,
160 + .lp = LZMA_OPT_LP_DEFAULT,
161 + .pb = LZMA_OPT_PB_DEFAULT,
162 + .fb = LZMA_OPT_FB_DEFAULT,
166 +static float lzma_dict_percent = 0;
168 +struct lzma_xz_options *lzma_xz_get_options(void)
174 +int lzma_xz_options(char *argv[], int argc, int lzmaver)
176 + const char *comp_name = lzmaver_str[lzmaver];
178 + if(strcmp(argv[0], "-Xpreset") == 0) {
182 + fprintf(stderr, "%s: -Xpreset missing preset\n", comp_name);
186 + preset = atoi(argv[1]);
188 + if (preset < 0 || preset > 9) {
189 + fprintf(stderr, "%s: -Xpreset invalid value\n", comp_name);
192 + options.preset = preset;
194 + } else if(strcmp(argv[0], "-Xe") == 0) {
195 + options.extreme = 1;
197 + } else if(strcmp(argv[0], "-Xlc") == 0) {
201 + fprintf(stderr, "%s: -Xlc missing lc\n", comp_name);
205 + lc = atoi(argv[1]);
207 + if (lc < LZMA_OPT_LC_MIN || lc > LZMA_OPT_LC_MAX) {
208 + fprintf(stderr, "%s: -Xlc invalid value\n", comp_name);
213 + } else if(strcmp(argv[0], "-Xlp") == 0) {
217 + fprintf(stderr, "%s: -Xlp missing lp\n", comp_name);
221 + lp = atoi(argv[1]);
223 + if (lp < LZMA_OPT_LP_MIN || lp > LZMA_OPT_LP_MAX) {
224 + fprintf(stderr, "%s: -Xlp invalid value\n", comp_name);
229 + } else if(strcmp(argv[0], "-Xpb") == 0) {
233 + fprintf(stderr, "%s: -Xpb missing pb\n", comp_name);
237 + pb = atoi(argv[1]);
239 + if (pb < LZMA_OPT_PB_MIN || pb > LZMA_OPT_PB_MAX) {
240 + fprintf(stderr, "%s: -Xbp invalid value\n", comp_name);
245 + } else if(strcmp(argv[0], "-Xfb") == 0) {
249 + fprintf(stderr, "%s: -Xfb missing fb\n", comp_name);
253 + fb = atoi(argv[1]);
255 + if (fb < LZMA_OPT_FB_MIN || fb > LZMA_OPT_FB_MAX) {
256 + fprintf(stderr, "%s: -Xfb invalid value\n", comp_name);
261 + } else if(strcmp(argv[0], "-Xdict-size") == 0) {
266 + fprintf(stderr, "%s: -Xdict-size missing dict-size\n", comp_name);
270 + size = strtof(argv[1], &b);
272 + if(size <= 0 || size > 100) {
273 + fprintf(stderr, "%s: -Xdict-size percentage "
274 + "should be 0 < dict-size <= 100\n", comp_name);
278 + lzma_dict_percent = size;
279 + options.dict_size = 0;
281 + if((float) ((int) size) != size) {
282 + fprintf(stderr, "%s: -Xdict-size can't be "
283 + "fractional unless a percentage of the"
284 + " block size\n", comp_name);
288 + lzma_dict_percent = 0;
289 + options.dict_size = (int) size;
291 + if(*b == 'k' || *b == 'K')
292 + options.dict_size *= 1024;
293 + else if(*b == 'm' || *b == 'M')
294 + options.dict_size *= 1024 * 1024;
295 + else if(*b != '\0') {
296 + fprintf(stderr, "%s: -Xdict-size invalid "
297 + "dict-size\n", comp_name);
312 +int lzma_xz_options_post(int block_size, int lzmaver)
314 + const char *comp_name = lzmaver_str[lzmaver];
316 + * if -Xdict-size has been specified use this to compute the datablock
319 + if(options.dict_size || lzma_dict_percent) {
320 + int dict_size_min = (lzmaver == 1 ? 4096 : 8192);
323 + if(options.dict_size) {
324 + if(options.dict_size > block_size) {
325 + fprintf(stderr, "%s: -Xdict-size is larger than"
326 + " block_size\n", comp_name);
330 + options.dict_size = block_size * lzma_dict_percent / 100;
332 + if(options.dict_size < dict_size_min) {
333 + fprintf(stderr, "%s: -Xdict-size should be %i bytes "
334 + "or larger\n", comp_name, dict_size_min);
339 + * dictionary_size must be storable in xz header as either
340 + * 2^n or as 2^n+2^(n+1)
342 + n = ffs(options.dict_size) - 1;
343 + if(options.dict_size != (1 << n) &&
344 + options.dict_size != ((1 << n) + (1 << (n + 1)))) {
345 + fprintf(stderr, "%s: -Xdict-size is an unsupported "
346 + "value, dict-size must be storable in %s "
347 + "header\n", comp_name, comp_name);
348 + fprintf(stderr, "as either 2^n or as 2^n+2^(n+1). "
349 + "Example dict-sizes are 75%%, 50%%, 37.5%%, "
351 + fprintf(stderr, "or 32K, 16K, 8K etc.\n");
356 + /* No -Xdict-size specified, use defaults */
357 + options.dict_size = block_size;
365 +static struct lzma_opts lzma_comp_opts;
367 +void *lzma_xz_dump_options(int block_size, int *size, int flags)
369 + /* No need to store default options */
370 + if (options.preset == 6 &&
371 + options.extreme == 0 &&
372 + options.lc == LZMA_OPT_LC_DEFAULT &&
373 + options.lp == LZMA_OPT_LC_DEFAULT &&
374 + options.pb == LZMA_OPT_PB_DEFAULT &&
376 + options.dict_size == block_size &&
380 + *size = sizeof(struct lzma_opts);
382 + lzma_comp_opts.flags |= flags;
384 + if (options.extreme)
385 + lzma_comp_opts.flags |= LZMA_OPT_EXTREME;
387 + lzma_comp_opts.flags |= ((options.preset << LZMA_OPT_PRE_OFF) & LZMA_OPT_PRE_MASK);
389 + lzma_comp_opts.bit_opts =
390 + ((options.lc << LZMA_OPT_LC_OFF) & LZMA_OPT_LC_MASK) |
391 + ((options.lp << LZMA_OPT_LP_OFF) & LZMA_OPT_LP_MASK) |
392 + ((options.pb << LZMA_OPT_PB_OFF) & LZMA_OPT_PB_MASK);
393 + lzma_comp_opts.fb = options.fb;
394 + lzma_comp_opts.dict_size = options.dict_size;
396 + SQUASHFS_INSWAP_LZMA_COMP_OPTS(&lzma_comp_opts);
398 + return &lzma_comp_opts;
401 +int lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver)
404 + /* default options */
405 + options.preset = 6;
406 + options.extreme = 0;
407 + options.lc = LZMA_OPT_LC_DEFAULT;
408 + options.lp = LZMA_OPT_LC_DEFAULT;
409 + options.pb = LZMA_OPT_PB_DEFAULT;
410 + options.fb = LZMA_OPT_FB_DEFAULT;
411 + options.dict_size = block_size;
414 + struct lzma_opts *comp_opts = buffer;
417 + if (size != sizeof(struct lzma_opts))
420 + SQUASHFS_INSWAP_LZMA_COMP_OPTS(comp_opts);
422 + options.flags = comp_opts->flags & LZMA_OPT_FLT_MASK;
423 + options.preset = (comp_opts->flags & LZMA_OPT_PRE_MASK) >> LZMA_OPT_PRE_OFF;
424 + options.extreme = !!(comp_opts->flags & LZMA_OPT_EXTREME);
426 + options.lc = (comp_opts->bit_opts & LZMA_OPT_LC_MASK) >> LZMA_OPT_LC_OFF;
427 + options.lp = (comp_opts->bit_opts & LZMA_OPT_LP_MASK) >> LZMA_OPT_LP_OFF;
428 + options.pb = (comp_opts->bit_opts & LZMA_OPT_PB_MASK) >> LZMA_OPT_PB_OFF;
429 + options.fb = comp_opts->fb;
430 + options.dict_size = comp_opts->dict_size;
432 + /* check that the LZMA bit options are in range */
433 + if (options.lc < LZMA_OPT_LC_MIN || options.lc > LZMA_OPT_LC_MAX ||
434 + options.lp < LZMA_OPT_LP_MIN || options.lp > LZMA_OPT_LP_MAX ||
435 + options.pb < LZMA_OPT_PB_MIN || options.pb > LZMA_OPT_PB_MAX ||
436 + options.fb < LZMA_OPT_FB_MIN || options.fb > LZMA_OPT_FB_MAX)
440 + * check that the dictionary size seems correct - the dictionary
441 + * size should 2^n or 2^n+2^(n+1)
443 + n = ffs(options.dict_size) - 1;
444 + if(options.dict_size != (1 << n) &&
445 + options.dict_size != ((1 << n) + (1 << (n + 1))))
453 + fprintf(stderr, "%s: error reading stored compressor options from "
454 + "filesystem!\n", lzmaver_str[lzmaver]);
458 +void lzma_xz_usage(int lzmaver)
460 + fprintf(stderr, "\t -Xpreset <preset>\n");
461 + fprintf(stderr, "\t\tcompression preset (0-9, default 6)\n");
462 + fprintf(stderr, "\t -Xe\n");
463 + fprintf(stderr, "\t\tTry to improve compression ratio by using more ");
464 + fprintf(stderr, "CPU time.\n");
465 + fprintf(stderr, "\t -Xlc <lc>\n");
466 + fprintf(stderr, "\t\tNumber of literal context bits (0-4, default 3)\n");
467 + fprintf(stderr, "\t -Xlp <lp>\n");
468 + fprintf(stderr, "\t\tNumber of literal position bits (0-4, default 0)\n");
469 + fprintf(stderr, "\t -Xpb <pb>\n");
470 + fprintf(stderr, "\t\tNumber of position bits (0-4, default 2)\n");
471 + fprintf(stderr, "\t -Xnice <nice>\n");
472 + fprintf(stderr, "\t\tNice length of a match (5-273, default 64)\n");
473 + fprintf(stderr, "\t -Xdict-size <dict-size>\n");
474 + fprintf(stderr, "\t\tUse <dict-size> as the %s dictionary size. The",
475 + lzmaver == LZMA_OPT_LZMA ? "LZMA" : "XZ");
476 + fprintf(stderr, " dictionary size\n\t\tcan be specified as a");
477 + fprintf(stderr, " percentage of the block size, or as an\n\t\t");
478 + fprintf(stderr, "absolute value. The dictionary size must be less");
479 + fprintf(stderr, " than or equal\n\t\tto the block size and %d bytes",
480 + lzmaver == LZMA_OPT_LZMA ? 4096 : 8192);
481 + fprintf(stderr, " or larger. It must also be\n\t\tstorable in the lzma");
482 + fprintf(stderr, " header as either 2^n or as 2^n+2^(n+1).\n\t\t");
483 + fprintf(stderr, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or");
484 + fprintf(stderr, " 32K, 16K, 8K\n\t\tetc.\n");
487 --- a/squashfs-tools/lzma_xz_wrapper.c
488 +++ b/squashfs-tools/lzma_xz_wrapper.c
491 #include "squashfs_fs.h"
492 #include "compressor.h"
493 +#include "lzma_xz_options.h"
495 #define LZMA_PROPS_SIZE 5
496 #define LZMA_UNCOMP_SIZE 8
498 static int lzma_compress(void *dummy, void *dest, void *src, int size,
499 int block_size, int *error)
502 unsigned char *d = (unsigned char *) dest;
503 + struct lzma_xz_options *opts = lzma_xz_get_options();
505 lzma_options_lzma opt;
506 lzma_stream strm = LZMA_STREAM_INIT;
509 - lzma_lzma_preset(&opt, LZMA_OPTIONS);
510 - opt.dict_size = block_size;
511 + preset = opts->preset;
514 + preset |= LZMA_PRESET_EXTREME;
516 + lzma_lzma_preset(&opt, opts->preset);
521 + opt.nice_len = opts->fb;
523 + opt.dict_size = opts->dict_size;
525 res = lzma_alone_encoder(&strm, &opt);
527 @@ -143,13 +158,45 @@ failed:
531 +static int lzma_options(char *argv[], int argc)
533 + return lzma_xz_options(argv, argc, LZMA_OPT_LZMA);
537 +static int lzma_options_post(int block_size)
539 + return lzma_xz_options_post(block_size, LZMA_OPT_LZMA);
543 +static void *lzma_dump_options(int block_size, int *size)
545 + return lzma_xz_dump_options(block_size, size, 0);
549 +static int lzma_extract_options(int block_size, void *buffer, int size)
551 + return lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_LZMA);
557 + lzma_xz_usage(LZMA_OPT_LZMA);
561 struct compressor lzma_comp_ops = {
563 .compress = lzma_compress,
564 .uncompress = lzma_uncompress,
567 + .options = lzma_options,
568 + .options_post = lzma_options_post,
569 + .dump_options = lzma_dump_options,
570 + .extract_options = lzma_extract_options,
571 + .usage = lzma_usage,
572 .id = LZMA_COMPRESSION,
575 --- a/squashfs-tools/xz_wrapper.h
576 +++ b/squashfs-tools/xz_wrapper.h
582 -#define __BYTE_ORDER BYTE_ORDER
583 -#define __BIG_ENDIAN BIG_ENDIAN
584 -#define __LITTLE_ENDIAN LITTLE_ENDIAN
589 -#if __BYTE_ORDER == __BIG_ENDIAN
590 -extern unsigned int inswap_le32(unsigned int);
592 -#define SQUASHFS_INSWAP_COMP_OPTS(s) { \
593 - (s)->dictionary_size = inswap_le32((s)->dictionary_size); \
594 - (s)->flags = inswap_le32((s)->flags); \
597 -#define SQUASHFS_INSWAP_COMP_OPTS(s)
600 #define MEMLIMIT (32 * 1024 * 1024)
603 --- a/squashfs-tools/xz_wrapper.c
604 +++ b/squashfs-tools/xz_wrapper.c
606 #include "squashfs_fs.h"
607 #include "xz_wrapper.h"
608 #include "compressor.h"
609 +#include "lzma_xz_options.h"
611 static struct bcj bcj[] = {
612 { "x86", LZMA_FILTER_X86, 0 },
613 @@ -41,22 +42,18 @@ static struct bcj bcj[] = {
614 { NULL, LZMA_VLI_UNKNOWN, 0 }
617 -static struct comp_opts comp_opts;
619 static int filter_count = 1;
620 -static int dictionary_size = 0;
621 -static float dictionary_percent = 0;
624 static int xz_options(char *argv[], int argc)
629 if(strcmp(argv[0], "-Xbcj") == 0) {
634 fprintf(stderr, "xz: -Xbcj missing filter\n");
640 @@ -76,190 +73,50 @@ static int xz_options(char *argv[], int
642 if(bcj[i].name == NULL) {
643 fprintf(stderr, "xz: -Xbcj unrecognised "
650 - } else if(strcmp(argv[0], "-Xdict-size") == 0) {
655 - fprintf(stderr, "xz: -Xdict-size missing dict-size\n");
659 - size = strtof(argv[1], &b);
661 - if(size <= 0 || size > 100) {
662 - fprintf(stderr, "xz: -Xdict-size percentage "
663 - "should be 0 < dict-size <= 100\n");
667 - dictionary_percent = size;
668 - dictionary_size = 0;
670 - if((float) ((int) size) != size) {
671 - fprintf(stderr, "xz: -Xdict-size can't be "
672 - "fractional unless a percentage of the"
677 - dictionary_percent = 0;
678 - dictionary_size = (int) size;
680 - if(*b == 'k' || *b == 'K')
681 - dictionary_size *= 1024;
682 - else if(*b == 'm' || *b == 'M')
683 - dictionary_size *= 1024 * 1024;
684 - else if(*b != '\0') {
685 - fprintf(stderr, "xz: -Xdict-size invalid "
695 + return lzma_xz_options(argv, argc, LZMA_OPT_XZ);
705 static int xz_options_post(int block_size)
708 - * if -Xdict-size has been specified use this to compute the datablock
711 - if(dictionary_size || dictionary_percent) {
714 - if(dictionary_size) {
715 - if(dictionary_size > block_size) {
716 - fprintf(stderr, "xz: -Xdict-size is larger than"
721 - dictionary_size = block_size * dictionary_percent / 100;
723 - if(dictionary_size < 8192) {
724 - fprintf(stderr, "xz: -Xdict-size should be 8192 bytes "
730 - * dictionary_size must be storable in xz header as either
731 - * 2^n or as 2^n+2^(n+1)
733 - n = ffs(dictionary_size) - 1;
734 - if(dictionary_size != (1 << n) &&
735 - dictionary_size != ((1 << n) + (1 << (n + 1)))) {
736 - fprintf(stderr, "xz: -Xdict-size is an unsupported "
737 - "value, dict-size must be storable in xz "
739 - fprintf(stderr, "as either 2^n or as 2^n+2^(n+1). "
740 - "Example dict-sizes are 75%%, 50%%, 37.5%%, "
742 - fprintf(stderr, "or 32K, 16K, 8K etc.\n");
747 - /* No -Xdict-size specified, use defaults */
748 - dictionary_size = block_size;
754 + return lzma_xz_options_post(block_size, LZMA_OPT_XZ);
758 static void *xz_dump_options(int block_size, int *size)
763 - * don't store compressor specific options in file system if the
764 - * default options are being used - no compressor options in the
765 - * file system means the default options are always assumed
768 - * metadata dictionary size: SQUASHFS_METADATA_SIZE
769 - * datablock dictionary size: block_size
772 - if(dictionary_size == block_size && filter_count == 1)
776 for(i = 0; bcj[i].name; i++)
777 flags |= bcj[i].selected << i;
779 - comp_opts.dictionary_size = dictionary_size;
780 - comp_opts.flags = flags;
782 - SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);
784 - *size = sizeof(comp_opts);
786 + return lzma_xz_dump_options(block_size, size, flags);
790 static int xz_extract_options(int block_size, void *buffer, int size)
792 - struct comp_opts *comp_opts = buffer;
797 - dictionary_size = block_size;
800 - /* check passed comp opts struct is of the correct length */
801 - if(size != sizeof(struct comp_opts))
804 - SQUASHFS_INSWAP_COMP_OPTS(comp_opts);
806 - dictionary_size = comp_opts->dictionary_size;
807 - flags = comp_opts->flags;
810 - * check that the dictionary size seems correct - the dictionary
811 - * size should 2^n or 2^n+2^(n+1)
813 - n = ffs(dictionary_size) - 1;
814 - if(dictionary_size != (1 << n) &&
815 - dictionary_size != ((1 << n) + (1 << (n + 1))))
818 + int ret = lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_XZ);
821 - for(i = 0; bcj[i].name; i++) {
822 - if((flags >> i) & 1) {
823 - bcj[i].selected = 1;
826 - bcj[i].selected = 0;
829 + struct lzma_xz_options *opts = lzma_xz_get_options();
830 + for(i = 0; bcj[i].name; i++) {
831 + if((opts->flags >> i) & 1) {
832 + bcj[i].selected = 1;
835 + bcj[i].selected = 0;
842 - fprintf(stderr, "xz: error reading stored compressor options from "
850 @@ -268,6 +125,7 @@ static int xz_init(void **strm, int bloc
851 int i, j, filters = datablock ? filter_count : 1;
852 struct filter *filter = malloc(filters * sizeof(struct filter));
853 struct xz_stream *stream;
854 + struct lzma_xz_options *opts = lzma_xz_get_options();
858 @@ -281,7 +139,7 @@ static int xz_init(void **strm, int bloc
860 memset(filter, 0, filters * sizeof(struct filter));
862 - stream->dictionary_size = datablock ? dictionary_size :
863 + stream->dictionary_size = datablock ? opts->dict_size :
864 SQUASHFS_METADATA_SIZE;
866 filter[0].filter[0].id = LZMA_FILTER_LZMA2;
867 @@ -323,14 +181,25 @@ static int xz_compress(void *strm, void
869 struct xz_stream *stream = strm;
870 struct filter *selected = NULL;
871 + struct lzma_xz_options *opts = lzma_xz_get_options();
873 stream->filter[0].buffer = dest;
875 for(i = 0; i < stream->filters; i++) {
876 + uint32_t preset = opts->preset;
877 struct filter *filter = &stream->filter[i];
879 - if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
882 + preset |= LZMA_PRESET_EXTREME;
884 + if(lzma_lzma_preset(&stream->opt, preset))
887 + stream->opt.lc = opts->lc;
888 + stream->opt.lp = opts->lp;
889 + stream->opt.pb = opts->pb;
891 + stream->opt.nice_len = opts->fb;
893 stream->opt.dict_size = stream->dictionary_size;
895 @@ -384,22 +253,13 @@ static int xz_uncompress(void *dest, voi
899 + lzma_xz_usage(LZMA_OPT_XZ);
900 fprintf(stderr, "\t -Xbcj filter1,filter2,...,filterN\n");
901 fprintf(stderr, "\t\tCompress using filter1,filter2,...,filterN in");
902 fprintf(stderr, " turn\n\t\t(in addition to no filter), and choose");
903 fprintf(stderr, " the best compression.\n");
904 fprintf(stderr, "\t\tAvailable filters: x86, arm, armthumb,");
905 fprintf(stderr, " powerpc, sparc, ia64\n");
906 - fprintf(stderr, "\t -Xdict-size <dict-size>\n");
907 - fprintf(stderr, "\t\tUse <dict-size> as the XZ dictionary size. The");
908 - fprintf(stderr, " dictionary size\n\t\tcan be specified as a");
909 - fprintf(stderr, " percentage of the block size, or as an\n\t\t");
910 - fprintf(stderr, "absolute value. The dictionary size must be less");
911 - fprintf(stderr, " than or equal\n\t\tto the block size and 8192 bytes");
912 - fprintf(stderr, " or larger. It must also be\n\t\tstorable in the xz");
913 - fprintf(stderr, " header as either 2^n or as 2^n+2^(n+1).\n\t\t");
914 - fprintf(stderr, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or");
915 - fprintf(stderr, " 32K, 16K, 8K\n\t\tetc.\n");
919 --- a/squashfs-tools/Makefile
920 +++ b/squashfs-tools/Makefile
921 @@ -140,6 +140,8 @@ COMPRESSORS += xz
924 ifneq ($(LZMA_XZ_SUPPORT)$(XZ_SUPPORT),)
925 +MKSQUASHFS_OBJS += lzma_xz_options.o
926 +UNSQUASHFS_OBJS += lzma_xz_options.o
928 MKSQUASHFS_OBJS += $(LZMA_LIB)
929 UNSQUASHFS_OBJS += $(LZMA_LIB)