[PATCH 2/2] fs/squashfs: add support for ZSTD decompression
Joao Marcos Costa
joaomarcos.costa at bootlin.com
Tue Aug 11 15:17:55 CEST 2020
Add call to ZSTD's ZSTD_decompressDCtx(). In this use case, the caller
can upper bound the decompressed size, which will be the SquashFS data
block (or metadata block) size, so there is no need to use streaming
API.
Signed-off-by: Joao Marcos Costa <joaomarcos.costa at bootlin.com>
---
fs/squashfs/sqfs_decompressor.c | 39 +++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c
index 9285df5d3b..b5a9d92808 100644
--- a/fs/squashfs/sqfs_decompressor.c
+++ b/fs/squashfs/sqfs_decompressor.c
@@ -18,6 +18,10 @@
#include <u-boot/zlib.h>
#endif
+#if IS_ENABLED(CONFIG_ZSTD)
+#include <linux/zstd.h>
+#endif
+
#include "sqfs_decompressor.h"
#include "sqfs_filesystem.h"
#include "sqfs_utils.h"
@@ -39,6 +43,31 @@ static void zlib_decompression_status(int ret)
}
#endif
+#if IS_ENABLED(CONFIG_ZSTD)
+static int sqfs_zstd_decompress(void *dest, unsigned long dest_len,
+ void *source, u32 src_len)
+{
+ void *workspace;
+ ZSTD_DCtx *ctx;
+ size_t wsize;
+ int ret;
+
+ wsize = ZSTD_DCtxWorkspaceBound();
+
+ workspace = malloc(wsize);
+ if (!workspace)
+ return -ENOMEM;
+
+ ctx = ZSTD_initDCtx(workspace, wsize);
+
+ ret = ZSTD_decompressDCtx(ctx, dest, dest_len, source, src_len);
+
+ free(workspace);
+
+ return ZSTD_isError(ret);
+}
+#endif /* CONFIG_ZSTD */
+
int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
void *source, u32 src_len)
{
@@ -67,6 +96,16 @@ int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
break;
}
#endif
+#if IS_ENABLED(CONFIG_ZSTD)
+ case SQFS_COMP_ZSTD:
+ ret = sqfs_zstd_decompress(dest, *dest_len, source, src_len);
+ if (ret) {
+ printf("ZSTD Error code: %d\n", ZSTD_getErrorCode(ret));
+ return -EINVAL;
+ }
+
+ break;
+#endif /* CONFIG_ZSTD */
default:
printf("Error: unknown compression type.\n");
return -EINVAL;
--
2.17.1
More information about the U-Boot
mailing list