1 From dcb976fe4ee40e4bac8ae0dcc836629c625a6fd4 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 used to set the compression level.
8 -Xe can be used to set the 'EXTREME' flag to use the lzma compression
9 options tweaking additional settings on top of the compression level set.
18 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
20 squashfs-tools/xz_wrapper.c | 119 ++++++++++++++++++++++++++++++++++--
21 1 file changed, 115 insertions(+), 4 deletions(-)
23 --- a/squashfs-tools/xz_wrapper.c
24 +++ b/squashfs-tools/xz_wrapper.c
25 @@ -44,7 +44,10 @@ static struct bcj bcj[] = {
26 static int filter_count = 1;
27 static int dictionary_size = 0;
28 static float dictionary_percent = 0;
30 +static int preset = LZMA_PRESET_DEFAULT;
36 * This function is called by the options parsing code in mksquashfs.c
37 @@ -53,6 +56,11 @@ static float dictionary_percent = 0;
38 * Two specific options are supported:
47 * This function returns:
48 * >=0 (number of additional args parsed) on success
49 @@ -141,6 +149,85 @@ static int xz_options(char *argv[], int
53 + } else if(strcmp(argv[0], "-Xpreset") == 0) {
58 + fprintf(stderr, "xz: -Xpreset missing preset-level "
59 + "(valid value 0-9)\n");
63 + val = strtol(argv[1], &b, 10);
64 + if (*b != '\0' || (int) val < 0 || (int) val & ~LZMA_PRESET_LEVEL_MASK) {
65 + fprintf(stderr, "xz: -Xpreset can't be "
66 + "negative or more than the max preset\n");
70 + preset &= ~LZMA_PRESET_LEVEL_MASK;
71 + preset |= (int) val;
74 + } else if(strcmp(argv[0], "-Xe") == 0) {
75 + preset |= LZMA_PRESET_EXTREME;
78 + } else if(strcmp(argv[0], "-Xlc") == 0) {
83 + fprintf(stderr, "xz: -Xlc missing value\n");
87 + val = strtol(argv[1], &b, 10);
88 + if (*b != '\0' || (int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
89 + fprintf(stderr, "xz: -Xlc invalid value\n");
96 + } else if(strcmp(argv[0], "-Xlp") == 0) {
101 + fprintf(stderr, "xz: -Xlp missing value\n");
105 + val = strtol(argv[1], &b, 10);
106 + if (*b != '\0' || (int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
107 + fprintf(stderr, "xz: -Xlp invalid value\n");
114 + } else if(strcmp(argv[0], "-Xpb") == 0) {
119 + fprintf(stderr, "xz: -Xpb missing value\n");
123 + val = strtol(argv[1], &b, 10);
124 + if (*b != '\0' || (int) val < LZMA_PB_MIN || (int) val > LZMA_PB_MAX) {
125 + fprintf(stderr, "xz: -Xpb invalid value\n");
135 @@ -446,11 +533,20 @@ static int xz_compress(void *strm, void
136 for(i = 0; i < stream->filters; i++) {
137 struct filter *filter = &stream->filter[i];
139 - if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
141 + if(lzma_lzma_preset(&stream->opt, preset))
144 stream->opt.dict_size = stream->dictionary_size;
147 + stream->opt.lc = lc;
150 + stream->opt.lp = lp;
153 + stream->opt.pb = pb;
156 res = lzma_stream_buffer_encode(filter->filter,
157 LZMA_CHECK_CRC32, NULL, src, size, filter->buffer,
158 @@ -521,13 +617,28 @@ static void xz_usage(FILE *stream)
159 fprintf(stream, " header as either 2^n or as 2^n+2^(n+1).\n\t\t");
160 fprintf(stream, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or");
161 fprintf(stream, " 32K, 16K, 8K\n\t\tetc.\n");
162 + fprintf(stream, "\t -Xpreset <preset-level>\n");
163 + fprintf(stream, "\t\tUse <preset-value> as the custom preset to use");
164 + fprintf(stream, " on compress.\n\t\t<preset-level> should be 0 .. 9");
165 + fprintf(stream, " (default 6)\n");
166 + fprintf(stream, "\t -Xe\n");
167 + fprintf(stream, "\t\tEnable additional compression settings by passing");
168 + fprintf(stream, " the EXTREME\n\t\tflag to the compression flags.\n");
169 + fprintf(stream, "\t -Xlc <value>\n");
170 + fprintf(stream, "\t -Xlp <value>\n");
171 + fprintf(stream, "\t -Xpb <value>\n");
175 static int option_args(char *option)
177 if(strcmp(option, "-Xbcj") == 0 ||
178 - strcmp(option, "-Xdict-size") == 0)
179 + strcmp(option, "-Xdict-size") == 0 ||
180 + strcmp(option, "-Xpreset") == 0 ||
181 + strcmp(option, "-Xe") == 0 ||
182 + strcmp(option, "-Xlc") == 0 ||
183 + strcmp(option, "-Xlp") == 0 ||
184 + strcmp(option, "-Xpb") == 0)