ksmbd: update to latest 3.4.8 release
[openwrt/staging/dedeckeh.git] / tools / squashfs4 / patches / 100-xz_wrapper-support-multiple-lzma-configuration-optio.patch
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
5
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.
10
11 New option added:
12 -Xpreset
13 -Xe
14 -Xlc
15 -Xlp
16 -Xpb
17
18 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 ---
20 squashfs-tools/xz_wrapper.c | 119 ++++++++++++++++++++++++++++++++++--
21 1 file changed, 115 insertions(+), 4 deletions(-)
22
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;
29 -
30 +static int preset = LZMA_PRESET_DEFAULT;
31 +static int lc = -1;
32 +static int lp = -1;
33 +static int pb = -1;
34
35 /*
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:
39 * -Xbcj
40 * -Xdict-size
41 + * -Xpreset
42 + * -Xe
43 + * -Xlc
44 + * -Xlp
45 + * -Xpb
46 *
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
50 }
51
52 return 1;
53 + } else if(strcmp(argv[0], "-Xpreset") == 0) {
54 + char *b;
55 + long val;
56 +
57 + if(argc < 2) {
58 + fprintf(stderr, "xz: -Xpreset missing preset-level "
59 + "(valid value 0-9)\n");
60 + goto failed;
61 + }
62 +
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");
67 + goto failed;
68 + }
69 +
70 + preset &= ~LZMA_PRESET_LEVEL_MASK;
71 + preset |= (int) val;
72 +
73 + return 1;
74 + } else if(strcmp(argv[0], "-Xe") == 0) {
75 + preset |= LZMA_PRESET_EXTREME;
76 +
77 + return 0;
78 + } else if(strcmp(argv[0], "-Xlc") == 0) {
79 + char *b;
80 + long val;
81 +
82 + if(argc < 2) {
83 + fprintf(stderr, "xz: -Xlc missing value\n");
84 + goto failed;
85 + }
86 +
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");
90 + goto failed;
91 + }
92 +
93 + lc = (int) val;
94 +
95 + return 1;
96 + } else if(strcmp(argv[0], "-Xlp") == 0) {
97 + char *b;
98 + long val;
99 +
100 + if(argc < 2) {
101 + fprintf(stderr, "xz: -Xlp missing value\n");
102 + goto failed;
103 + }
104 +
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");
108 + goto failed;
109 + }
110 +
111 + lp = (int) val;
112 +
113 + return 1;
114 + } else if(strcmp(argv[0], "-Xpb") == 0) {
115 + char *b;
116 + long val;
117 +
118 + if(argc < 2) {
119 + fprintf(stderr, "xz: -Xpb missing value\n");
120 + goto failed;
121 + }
122 +
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");
126 + goto failed;
127 + }
128 +
129 + pb = (int) val;
130 +
131 + return 1;
132 }
133
134 return -1;
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];
138
139 - if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
140 - goto failed;
141 + if(lzma_lzma_preset(&stream->opt, preset))
142 + goto failed;
143
144 stream->opt.dict_size = stream->dictionary_size;
145
146 + if (lc >= 0)
147 + stream->opt.lc = lc;
148 +
149 + if (lp >= 0)
150 + stream->opt.lp = lp;
151 +
152 + if (pb >= 0)
153 + stream->opt.pb = pb;
154 +
155 filter->length = 0;
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");
172 }
173
174
175 static int option_args(char *option)
176 {
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)
185 return 1;
186
187 return 0;