1 From f49793cfbd72fdc40ab75dbffef42dca774701d1 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 14 Oct 2022 15:59:16 +0200
4 Subject: [PATCH] xz_wrapper: support multiple lzma configuration options
6 Add option to configure preset, lc, lp and pb lzma parameters.
7 -Xpreset can be both a level or set to 'extreme' to use the lzma extreme
16 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 squashfs-tools/xz_wrapper.c | 112 +++++++++++++++++++++++++++++++++++-
19 1 file changed, 109 insertions(+), 3 deletions(-)
21 --- a/squashfs-tools/xz_wrapper.c
22 +++ b/squashfs-tools/xz_wrapper.c
23 @@ -44,7 +44,10 @@ static struct bcj bcj[] = {
24 static int filter_count = 1;
25 static int dictionary_size = 0;
26 static float dictionary_percent = 0;
28 +static int preset = LZMA_PRESET_DEFAULT;
34 * This function is called by the options parsing code in mksquashfs.c
35 @@ -53,6 +56,11 @@ static float dictionary_percent = 0;
36 * Two specific options are supported:
45 * This function returns:
46 * >=0 (number of additional args parsed) on success
47 @@ -141,6 +149,85 @@ static int xz_options(char *argv[], int
51 + } else if(strcmp(argv[0], "-Xpreset") == 0) {
56 + fprintf(stderr, "xz: -Xpreset missing preset-level\n");
60 + if (strcmp(argv[1], "extreme") == 0) {
61 + preset = LZMA_PRESET_EXTREME;
66 + val = strtol(argv[1], &b, 10);
67 + if ((int) val < 0 || (int) val & ~LZMA_PRESET_LEVEL_MASK) {
68 + fprintf(stderr, "xz: -Xpreset can't be "
69 + "negative or more than the max preset\n");
76 + } else if(strcmp(argv[0], "-Xlc") == 0) {
81 + fprintf(stderr, "xz: -Xlc missing value\n");
85 + val = strtol(argv[1], &b, 10);
86 + if ((int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
87 + fprintf(stderr, "xz: -Xlc invalid value\n");
94 + } else if(strcmp(argv[0], "-Xlp") == 0) {
99 + fprintf(stderr, "xz: -Xlp missing value\n");
103 + val = strtol(argv[1], &b, 10);
104 + if ((int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
105 + fprintf(stderr, "xz: -Xlc invalid value\n");
112 + } else if(strcmp(argv[0], "-Xpb") == 0) {
117 + fprintf(stderr, "xz: -Xpb missing value\n");
121 + val = strtol(argv[1], &b, 10);
122 + if ((int) val < LZMA_PB_MIN || (int) val > LZMA_PB_MAX) {
123 + fprintf(stderr, "xz: -Xlc invalid value\n");
133 @@ -446,11 +533,20 @@ static int xz_compress(void *strm, void
134 for(i = 0; i < stream->filters; i++) {
135 struct filter *filter = &stream->filter[i];
137 - if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
138 + if(lzma_lzma_preset(&stream->opt, preset))
141 stream->opt.dict_size = stream->dictionary_size;
144 + stream->opt.lc = lc;
147 + stream->opt.lp = lp;
150 + stream->opt.pb = pb;
153 res = lzma_stream_buffer_encode(filter->filter,
154 LZMA_CHECK_CRC32, NULL, src, size, filter->buffer,
155 @@ -521,6 +617,12 @@ static void xz_usage(FILE *stream)
156 fprintf(stream, " header as either 2^n or as 2^n+2^(n+1).\n\t\t");
157 fprintf(stream, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or");
158 fprintf(stream, " 32K, 16K, 8K\n\t\tetc.\n");
159 + fprintf(stream, "\t -Xpreset <preset-level or extreme>\n");
160 + fprintf(stream, "\t\tUse <preset-value> as the custom preset to use");
161 + fprintf(stream, " on compress. Can be a level number or extreme.\n");
162 + fprintf(stream, "\t -Xlc <value>\n");
163 + fprintf(stream, "\t -Xlp <value>\n");
164 + fprintf(stream, "\t -Xpb <value>\n");