26
26
#include <linux/err.h>
27
27
#include <linux/lzo.h>
28
28
29
+ #if IS_ENABLED (CONFIG_ZSTD )
30
+ #include <linux/zstd.h>
31
+ #include <abuf.h>
32
+ #endif
33
+
29
34
DECLARE_GLOBAL_DATA_PTR ;
30
35
31
36
/* compress.c */
@@ -41,6 +46,25 @@ static int gzip_decompress(const unsigned char *in, size_t in_len,
41
46
(unsigned long * )out_len , 0 , 0 );
42
47
}
43
48
49
+ #if IS_ENABLED (CONFIG_ZSTD )
50
+ static int zstd_decompress_wrapper (const unsigned char * in , size_t in_len ,
51
+ unsigned char * out , size_t * out_len )
52
+ {
53
+ struct abuf abuf_in , abuf_out ;
54
+ int ret ;
55
+
56
+ abuf_init_set (& abuf_in , (void * )in , in_len );
57
+ abuf_init_set (& abuf_out , (void * )out , * out_len );
58
+
59
+ ret = zstd_decompress (& abuf_in , & abuf_out );
60
+ if (ret < 0 )
61
+ return ret ;
62
+
63
+ * out_len = ret ;
64
+ return 0 ;
65
+ }
66
+ #endif
67
+
44
68
/* Fake description object for the "none" compressor */
45
69
static struct ubifs_compressor none_compr = {
46
70
.compr_type = UBIFS_COMPR_NONE ,
@@ -70,8 +94,21 @@ static struct ubifs_compressor zlib_compr = {
70
94
.decompress = gzip_decompress ,
71
95
};
72
96
97
+ #if IS_ENABLED (CONFIG_ZSTD )
98
+ static struct ubifs_compressor zstd_compr = {
99
+ .compr_type = UBIFS_COMPR_ZSTD ,
100
+ #ifndef __UBOOT__
101
+ .comp_mutex = & zstd_enc_mutex ,
102
+ .decomp_mutex = & zstd_dec_mutex ,
103
+ #endif
104
+ .name = "zstd" ,
105
+ .capi_name = "zstd" ,
106
+ .decompress = zstd_decompress_wrapper ,
107
+ };
108
+ #endif
109
+
73
110
/* All UBIFS compressors */
74
- struct ubifs_compressor * ubifs_compressors [UBIFS_COMPR_TYPES_CNT ];
111
+ struct ubifs_compressor * ubifs_compressors [UBIFS_COMPR_TYPES_CNT ] = { NULL } ;
75
112
76
113
77
114
#ifdef __UBOOT__
@@ -165,8 +202,14 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
165
202
166
203
compr = ubifs_compressors [compr_type ];
167
204
205
+ if (unlikely (!compr )) {
206
+ ubifs_err (c , "compression type %d is not compiled in" , compr_type );
207
+ return - EINVAL ;
208
+ }
209
+
168
210
if (unlikely (!compr -> capi_name )) {
169
- ubifs_err (c , "%s compression is not compiled in" , compr -> name );
211
+ ubifs_err (c , "%s compression is not compiled in" ,
212
+ compr -> name ? compr -> name : "unknown" );
170
213
return - EINVAL ;
171
214
}
172
215
@@ -231,6 +274,12 @@ int __init ubifs_compressors_init(void)
231
274
if (err )
232
275
return err ;
233
276
277
+ #if IS_ENABLED (CONFIG_ZSTD )
278
+ err = compr_init (& zstd_compr );
279
+ if (err )
280
+ return err ;
281
+ #endif
282
+
234
283
err = compr_init (& none_compr );
235
284
if (err )
236
285
return err ;
0 commit comments