tools/squashfs4: bump to 4.6.1
[openwrt/staging/dedeckeh.git] / tools / squashfs4 / patches / 100-xz_wrapper-support-multiple-lzma-configuration-optio.patch
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
5
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
8 compression options.
9
10 New option added:
11 -Xpreset
12 -Xlc
13 -Xlp
14 -Xpb
15
16 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17 ---
18 squashfs-tools/xz_wrapper.c | 112 +++++++++++++++++++++++++++++++++++-
19 1 file changed, 109 insertions(+), 3 deletions(-)
20
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;
27 -
28 +static int preset = LZMA_PRESET_DEFAULT;
29 +static int lc = -1;
30 +static int lp = -1;
31 +static int pb = -1;
32
33 /*
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:
37 * -Xbcj
38 * -Xdict-size
39 + * -Xpreset
40 + * -Xe
41 + * -Xlc
42 + * -Xlp
43 + * -Xpb
44 *
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
48 }
49
50 return 1;
51 + } else if(strcmp(argv[0], "-Xpreset") == 0) {
52 + char *b;
53 + long val;
54 +
55 + if(argc < 2) {
56 + fprintf(stderr, "xz: -Xpreset missing preset-level\n");
57 + goto failed;
58 + }
59 +
60 + if (strcmp(argv[1], "extreme") == 0) {
61 + preset = LZMA_PRESET_EXTREME;
62 +
63 + return 1;
64 + }
65 +
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");
70 + goto failed;
71 + }
72 +
73 + preset = (int) val;
74 +
75 + return 1;
76 + } else if(strcmp(argv[0], "-Xlc") == 0) {
77 + char *b;
78 + long val;
79 +
80 + if(argc < 2) {
81 + fprintf(stderr, "xz: -Xlc missing value\n");
82 + goto failed;
83 + }
84 +
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");
88 + goto failed;
89 + }
90 +
91 + lc = (int) val;
92 +
93 + return 1;
94 + } else if(strcmp(argv[0], "-Xlp") == 0) {
95 + char *b;
96 + long val;
97 +
98 + if(argc < 2) {
99 + fprintf(stderr, "xz: -Xlp missing value\n");
100 + goto failed;
101 + }
102 +
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");
106 + goto failed;
107 + }
108 +
109 + lp = (int) val;
110 +
111 + return 1;
112 + } else if(strcmp(argv[0], "-Xpb") == 0) {
113 + char *b;
114 + long val;
115 +
116 + if(argc < 2) {
117 + fprintf(stderr, "xz: -Xpb missing value\n");
118 + goto failed;
119 + }
120 +
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");
124 + goto failed;
125 + }
126 +
127 + pb = (int) val;
128 +
129 + return 1;
130 }
131
132 return -1;
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];
136
137 - if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
138 + if(lzma_lzma_preset(&stream->opt, preset))
139 goto failed;
140
141 stream->opt.dict_size = stream->dictionary_size;
142
143 + if (lc >= 0)
144 + stream->opt.lc = lc;
145 +
146 + if (lp >= 0)
147 + stream->opt.lp = lp;
148 +
149 + if (pb >= 0)
150 + stream->opt.pb = pb;
151 +
152 filter->length = 0;
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");
165 }
166
167