squashfs4: make the lzma parameters configurable, and change the defaults for slightl...
[openwrt/svn-archive/archive.git] / tools / squashfs4 / patches / 130-dynamic_lzma_params.patch
1 --- a/squashfs-tools/lzma_wrapper.c
2 +++ b/squashfs-tools/lzma_wrapper.c
3 @@ -20,6 +20,8 @@
4 */
5
6 #include <LzmaLib.h>
7 +#include <stdio.h>
8 +#include "compressor.h"
9
10 #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
11
12 @@ -30,9 +32,18 @@
13 size_t props_size = LZMA_PROPS_SIZE,
14 outlen = block_size - LZMA_HEADER_SIZE;
15 int res;
16 + int lc;
17 + int lp;
18 + int pb;
19 +
20 + if (!comp_args || sscanf(comp_args, "%d:%d:%d", &lc, &lp, &pb) != 3) {
21 + lc = 0;
22 + lp = 2;
23 + pb = 2;
24 + }
25
26 res = LzmaCompress(d + LZMA_HEADER_SIZE, &outlen, s, size, d,
27 - &props_size, 5, block_size, 3, 0, 2, 32, 1);
28 + &props_size, 5, block_size, lc, lp, pb, 32, 1);
29
30 if(res == SZ_ERROR_OUTPUT_EOF) {
31 /*
32 --- a/squashfs-tools/compressor.c
33 +++ b/squashfs-tools/compressor.c
34 @@ -25,6 +25,7 @@
35 #include "compressor.h"
36 #include "squashfs_fs.h"
37
38 +char *comp_args = NULL;
39 extern int gzip_compress(void **, char *, char *, int, int, int *);
40 extern int gzip_uncompress(char *, char *, int, int, int *);
41 extern int lzma_compress(void **, char *, char *, int, int, int *);
42 --- a/squashfs-tools/compressor.h
43 +++ b/squashfs-tools/compressor.h
44 @@ -31,3 +31,4 @@
45 extern struct compressor *lookup_compressor(char *);
46 extern struct compressor *lookup_compressor_id(int);
47 extern void display_compressors(char *, char *);
48 +extern char *comp_args;
49 --- a/squashfs-tools/mksquashfs.c
50 +++ b/squashfs-tools/mksquashfs.c
51 @@ -4355,6 +4355,12 @@
52 exit(1);
53 }
54 comp_name = argv[i];
55 + } else if(strcmp(argv[i], "-comp_args") == 0) {
56 + if(++i == argc) {
57 + ERROR("%s: -comp_args missing compression arguments\n", argv[0]);
58 + exit(1);
59 + }
60 + comp_args = argv[i];
61 } else if(strcmp(argv[i], "-pf") == 0) {
62 if(++i == argc) {
63 ERROR("%s: -pf missing filename\n", argv[0]);
64 @@ -4574,6 +4580,7 @@
65 "[-e list of exclude\ndirs/files]\n", argv[0]);
66 ERROR("\nFilesystem build options:\n");
67 ERROR("-comp <comp>\t\tselect <comp> compression\n");
68 + ERROR("-comp_args <comp>\t\tselect compression arguments\n");
69 ERROR("\t\t\tCompressors available:\n");
70 display_compressors("\t\t\t", COMP_DEFAULT);
71 ERROR("-b <block_size>\t\tset data block to "
72 @@ -4736,7 +4743,8 @@
73 else if(strcmp(argv[i], "-root-becomes") == 0 ||
74 strcmp(argv[i], "-sort") == 0 ||
75 strcmp(argv[i], "-pf") == 0 ||
76 - strcmp(argv[i], "-comp") == 0)
77 + strcmp(argv[i], "-comp") == 0 ||
78 + strcmp(argv[i], "-comp_args") == 0)
79 i++;
80
81 if(i != argc) {
82 @@ -4761,7 +4769,8 @@
83 else if(strcmp(argv[i], "-root-becomes") == 0 ||
84 strcmp(argv[i], "-ef") == 0 ||
85 strcmp(argv[i], "-pf") == 0 ||
86 - strcmp(argv[i], "-comp") == 0)
87 + strcmp(argv[i], "-comp") == 0 ||
88 + strcmp(argv[i], "-comp_args") == 0)
89 i++;
90
91 #ifdef SQUASHFS_TRACE