Support LibreELEC 11.0+ (#2281)

This commit is contained in:
longpanda
2023-03-09 23:59:12 +08:00
parent d8698b2194
commit b47aa1abc7
4 changed files with 54 additions and 4 deletions

View File

@@ -1533,7 +1533,7 @@ module = {
name = squash4;
common = fs/squash4.c;
cflags = '$(CFLAGS_POSIX) -Wno-undef';
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H';
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -I$(srcdir)/lib/minilzo -I$(srcdir)/lib/zstd -DMINILZO_HAVE_CONFIG_H';
};
module = {

View File

@@ -27,6 +27,7 @@
#include <grub/fshelp.h>
#include <grub/deflate.h>
#include <minilzo.h>
#include <zstd.h>
#include "xz.h"
#include "xz_stream.h"
@@ -184,6 +185,7 @@ enum
COMPRESSION_LZO = 3,
COMPRESSION_XZ = 4,
COMPRESSION_LZ4 = 5,
COMPRESSION_ZSTD = 6,
};
@@ -398,6 +400,33 @@ static grub_ssize_t lz4_decompress_wrap(char *inbuf, grub_size_t insize, grub_of
return len;
}
static grub_ssize_t zstd_decompress_wrap(char *inbuf, grub_size_t insize, grub_off_t off,
char *outbuf, grub_size_t len, struct grub_squash_data *data)
{
char *udata = NULL;
int usize = data->blksz;
if (off == 0)
{
ZSTD_decompress(outbuf, len, inbuf, insize);
}
else
{
if (usize < 8192)
usize = 8192;
udata = grub_malloc (usize);
if (!udata)
return -1;
ZSTD_decompress(udata, usize, inbuf, insize);
grub_memcpy(outbuf, udata + off, len);
grub_free(udata);
}
return len;
}
static struct grub_squash_data *
squash_mount (grub_disk_t disk)
{
@@ -447,6 +476,9 @@ squash_mount (grub_disk_t disk)
case grub_cpu_to_le16_compile_time (COMPRESSION_LZ4):
data->decompress = lz4_decompress_wrap;
break;
case grub_cpu_to_le16_compile_time (COMPRESSION_ZSTD):
data->decompress = zstd_decompress_wrap;
break;
case grub_cpu_to_le16_compile_time (COMPRESSION_XZ):
data->decompress = xz_decompress;
data->xzbuf = grub_malloc (XZBUFSIZ);