mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-21 14:59:34 +00:00
fs/zfs/zfs: Add support for zstd compression
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
1 parent
55d35d6283
commit
f96df6fe9f
3 files changed
+40
No files matched your search
@@ -1601,6 +1601,7 @@ module = {
|
|||||||
common = fs/zfs/zfs_lz4.c;
|
common = fs/zfs/zfs_lz4.c;
|
||||||
common = fs/zfs/zfs_sha256.c;
|
common = fs/zfs/zfs_sha256.c;
|
||||||
common = fs/zfs/zfs_fletcher.c;
|
common = fs/zfs/zfs_fletcher.c;
|
||||||
|
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd';
|
||||||
};
|
};
|
||||||
|
|
||||||
module = {
|
module = {
|
||||||
|
|||||||
@@ -57,6 +57,8 @@
|
|||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
#include <grub/safemath.h>
|
#include <grub/safemath.h>
|
||||||
|
|
||||||
|
#include <zstd.h>
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
#define ZPOOL_PROP_BOOTFS "bootfs"
|
#define ZPOOL_PROP_BOOTFS "bootfs"
|
||||||
@@ -293,6 +295,7 @@ static const char *spa_feature_names[] = {
|
|||||||
"org.open-zfs:large_blocks",
|
"org.open-zfs:large_blocks",
|
||||||
"com.klarasystems:vdev_zaps_v2",
|
"com.klarasystems:vdev_zaps_v2",
|
||||||
"com.delphix:head_errlog",
|
"com.delphix:head_errlog",
|
||||||
|
"org.freebsd:zstd_compress",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -314,6 +317,40 @@ zlib_decompress (void *s, void *d,
|
|||||||
return grub_errno;
|
return grub_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static grub_err_t
|
||||||
|
zstd_decompress (void *ibuf, void *obuf, grub_size_t isize,
|
||||||
|
grub_size_t osize)
|
||||||
|
{
|
||||||
|
grub_size_t zstd_ret;
|
||||||
|
grub_uint32_t c_len;
|
||||||
|
grub_uint8_t *byte_buf = (grub_uint8_t *) ibuf;
|
||||||
|
|
||||||
|
if (isize < 8)
|
||||||
|
return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data too short");
|
||||||
|
|
||||||
|
c_len = grub_be_to_cpu32 (grub_get_unaligned32 (byte_buf));
|
||||||
|
|
||||||
|
if (c_len > isize - 8)
|
||||||
|
return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
|
||||||
|
"zstd data announced size overflow");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ZFS uses non-stadard magic for zstd streams. Rather than adjusting
|
||||||
|
* library functions, replace non-standard magic with standard one.
|
||||||
|
*/
|
||||||
|
byte_buf[4] = 0x28;
|
||||||
|
byte_buf[5] = 0xb5;
|
||||||
|
byte_buf[6] = 0x2f;
|
||||||
|
byte_buf[7] = 0xfd;
|
||||||
|
zstd_ret = ZSTD_decompress (obuf, osize, byte_buf + 4, c_len + 4);
|
||||||
|
|
||||||
|
if (ZSTD_isError (zstd_ret))
|
||||||
|
return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
|
||||||
|
"zstd data corrupted (error %d)", (int) zstd_ret);
|
||||||
|
|
||||||
|
return GRUB_ERR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
zle_decompress (void *s, void *d,
|
zle_decompress (void *s, void *d,
|
||||||
grub_size_t slen, grub_size_t dlen)
|
grub_size_t slen, grub_size_t dlen)
|
||||||
@@ -364,6 +401,7 @@ static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = {
|
|||||||
{"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */
|
{"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */
|
||||||
{"zle", zle_decompress}, /* ZIO_COMPRESS_ZLE */
|
{"zle", zle_decompress}, /* ZIO_COMPRESS_ZLE */
|
||||||
{"lz4", lz4_decompress}, /* ZIO_COMPRESS_LZ4 */
|
{"lz4", lz4_decompress}, /* ZIO_COMPRESS_LZ4 */
|
||||||
|
{"zstd", zstd_decompress}, /* ZIO_COMPRESS_ZSTD */
|
||||||
};
|
};
|
||||||
|
|
||||||
static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
|
static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ enum zio_compress {
|
|||||||
ZIO_COMPRESS_GZIP9,
|
ZIO_COMPRESS_GZIP9,
|
||||||
ZIO_COMPRESS_ZLE,
|
ZIO_COMPRESS_ZLE,
|
||||||
ZIO_COMPRESS_LZ4,
|
ZIO_COMPRESS_LZ4,
|
||||||
|
ZIO_COMPRESS_ZSTD,
|
||||||
ZIO_COMPRESS_FUNCTIONS
|
ZIO_COMPRESS_FUNCTIONS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user