aboutsummaryrefslogtreecommitdiffstats
path: root/tools/squashfs4/patches/101-xz_wrapper-support-multiple-lzma-configuration-optio.patch
blob: c882529cad34ac1135fe95596d2989186e45b521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
From f49793cfbd72fdc40ab75dbffef42dca774701d1 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Fri, 14 Oct 2022 15:59:16 +0200
Subject: [PATCH] xz_wrapper: support multiple lzma configuration options

Add option to configure preset, lc, lp and pb lzma parameters.
-Xpreset can be both a level or set to 'extreme' to use the lzma extreme
compression options.

New option added:
 -Xpreset
 -Xlc
 -Xlp
 -Xpb

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 squashfs-tools/xz_wrapper.c | 112 +++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 3 deletions(-)

--- a/squashfs-tools/xz_wrapper.c
+++ b/squashfs-tools/xz_wrapper.c
@@ -44,7 +44,10 @@ static struct bcj bcj[] = {
 static int filter_count = 1;
 static int dictionary_size = 0;
 static float dictionary_percent = 0;
-
+static int preset = LZMA_PRESET_DEFAULT;
+static int lc = -1;
+static int lp = -1;
+static int pb = -1;
 
 /*
  * This function is called by the options parsing code in mksquashfs.c
@@ -53,6 +56,11 @@ static float dictionary_percent = 0;
  * Two specific options are supported:
  *	-Xbcj
  *	-Xdict-size
+ *	-Xpreset
+ *	-Xe
+ *	-Xlc
+ *	-Xlp
+ *	-Xpb
  *
  * This function returns:
  *	>=0 (number of additional args parsed) on success
@@ -141,6 +149,85 @@ static int xz_options(char *argv[], int
 		}
 
 		return 1;
+	} else if(strcmp(argv[0], "-Xpreset") == 0) {
+		char *b;
+		long val;
+
+		if(argc < 2) {
+			fprintf(stderr, "xz: -Xpreset missing preset-level\n");
+			goto failed;
+		}
+
+		if (strcmp(argv[1], "extreme") == 0) {
+			preset = LZMA_PRESET_EXTREME;
+
+			return 1;
+		}
+
+		val = strtol(argv[1], &b, 10);
+		if ((int) val < 0 || (int) val & ~LZMA_PRESET_LEVEL_MASK) {
+			fprintf(stderr, "xz: -Xpreset can't be "
+				"negative or more than the max preset\n");
+			goto failed;
+		}
+
+		preset = (int) val;
+
+		return 1;
+	} else if(strcmp(argv[0], "-Xlc") == 0) {
+		char *b;
+		long val;
+
+		if(argc < 2) {
+			fprintf(stderr, "xz: -Xlc missing value\n");
+			goto failed;
+		}
+
+		val = strtol(argv[1], &b, 10);
+		if ((int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
+			fprintf(stderr, "xz: -Xlc invalid value\n");
+			goto failed;
+		}
+
+		lc = (int) val;
+
+		return 1;
+	} else if(strcmp(argv[0], "-Xlp") == 0) {
+		char *b;
+		long val;
+
+		if(argc < 2) {
+			fprintf(stderr, "xz: -Xlp missing value\n");
+			goto failed;
+		}
+
+		val = strtol(argv[1], &b, 10);
+		if ((int) val < LZMA_LCLP_MIN || (int) val > LZMA_LCLP_MAX) {
+			fprintf(stderr, "xz: -Xlc invalid value\n");
+			goto failed;
+		}
+
+		lp = (int) val;
+
+		return 1;
+	} else if(strcmp(argv[0], "-Xpb") == 0) {
+		char *b;
+		long val;
+
+		if(argc < 2) {
+			fprintf(stderr, "xz: -Xpb missing value\n");
+			goto failed;
+		}
+
+		val = strtol(argv[1], &b, 10);
+		if ((int) val < LZMA_PB_MIN || (int) val > LZMA_PB_MAX) {
+			fprintf(stderr, "xz: -Xlc invalid value\n");
+			goto failed;
+		}
+
+		pb = (int) val;
+
+		return 1;
 	}
 
 	return -1;
@@ -446,11 +533,20 @@ static int xz_compress(void *strm, void
 	for(i = 0; i < stream->filters; i++) {
 		struct filter *filter = &stream->filter[i];
 
-        	if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))
+        	if(lzma_lzma_preset(&stream->opt, preset))
                 	goto failed;
 
 		stream->opt.dict_size = stream->dictionary_size;
 
+		if (lc >= 0)
+			stream->opt.lc = lc;
+
+		if (lp >= 0)
+			stream->opt.lp = lp;
+
+		if (pb >= 0)
+			stream->opt.pb = pb;
+
 		filter->length = 0;
 		res = lzma_stream_buffer_encode(filter->filter,
 			LZMA_CHECK_CRC32, NULL, src, size, filter->buffer,
@@ -521,6 +617,12 @@ static void xz_usage(FILE *stream)
 	fprintf(stream, " header as either 2^n or as 2^n+2^(n+1).\n\t\t");
 	fprintf(stream, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or");
 	fprintf(stream, " 32K, 16K, 8K\n\t\tetc.\n");
+	fprintf(stream, "\t  -Xpreset <preset-level or extreme>\n");
+	fprintf(stream, "\t\tUse <preset-value> as the custom preset to use");
+	fprintf(stream, "  on compress. Can be a level number or extreme.\n");
+	fprintf(stream, "\t  -Xlc <value>\n");
+	fprintf(stream, "\t  -Xlp <value>\n");
+	fprintf(stream, "\t  -Xpb <value>\n");
 }