Skip to contentSkip to conversation

fs/squashfs: enable LZ4 compression support

PATCH In review David Oberhollenzer 3 participants 3 messages Nov 6, 2023 – Nov 17, 2023 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/squashfs: enable LZ4 compression support

The structure is identical to the existing compressor implementations, trivially adding lz4 decompression to sqfs_decompress.

The changes were tested using a sandbox build. An LZ4 compressed squashfs image was bound as a host block device.

---
 fs/squashfs/sqfs_decompressor.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/squashfs/sqfs_decompressor.c +23 -0
index 6b3e01cdad..cfd1153fd7 100644
@@ -18,6 +18,10 @@
 #include <u-boot/zlib.h>
 #endif
 
+#if IS_ENABLED(CONFIG_LZ4)
+#include <u-boot/lz4.h>
+#endif
+
 #if IS_ENABLED(CONFIG_ZSTD)
 #include <linux/zstd.h>
 #endif
@@ -38,6 +42,10 @@ int sqfs_decompressor_init(struct squashfs_ctxt *ctxt)
 	case SQFS_COMP_ZLIB:
 		break;
 #endif
+#if IS_ENABLED(CONFIG_LZ4)
+	case SQFS_COMP_LZ4:
+		break;
+#endif
 #if IS_ENABLED(CONFIG_ZSTD)
 	case SQFS_COMP_ZSTD:
 		ctxt->zstd_workspace = malloc(zstd_dctx_workspace_bound());
@@ -66,6 +74,10 @@ void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt)
 	case SQFS_COMP_ZLIB:
 		break;
 #endif
+#if IS_ENABLED(CONFIG_LZ4)
+	case SQFS_COMP_LZ4:
+		break;
+#endif
 #if IS_ENABLED(CONFIG_ZSTD)
 	case SQFS_COMP_ZSTD:
 		free(ctxt->zstd_workspace);
@@ -139,6 +151,17 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
 
 		break;
 #endif
+#if IS_ENABLED(CONFIG_LZ4)
+	case SQFS_COMP_LZ4:
+		ret = LZ4_decompress_safe(source, dest, src_len, *dest_len);
+		if (ret < 0) {
+			printf("LZ4 decompression failed.\n");
+			return -EINVAL;
+		}
+
+		ret = 0;
+		break;
+#endif
 #if IS_ENABLED(CONFIG_ZSTD)
 	case SQFS_COMP_ZSTD:
 		ret = sqfs_zstd_decompress(ctxt, dest, *dest_len, source, src_len);
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw

Hello, David

Thanks for this contribution!

Em seg., 6 de nov. de 2023 às 11:15, David Oberhollenzer < [email protected]> escreveu:

Quoted 9 lines

The structure is identical to the existing compressor implementations, trivially adding lz4 decompression to sqfs_decompress.

The changes were tested using a sandbox build. An LZ4 compressed squashfs image was bound as a host block device.

---

[...]

Signature · 5 lines
Atenciosamente,
João Marcos Costa

www.linkedin.com/in/jmarcoscosta/
https://github.com/jmarcoscosta
#2 lore raw
In reply to David Oberhollenzer
Quoted 8 lines · David Oberhollenzer

The structure is identical to the existing compressor implementations, trivially adding lz4 decompression to sqfs_decompress.

The changes were tested using a sandbox build. An LZ4 compressed squashfs image was bound as a host block device.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom