lib/xz: preliminary EROFS LZMA support v0.2
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH 1/1 lib/xz: preliminary EROFS LZMA support v0.2
From: Lasse Collin <[email protected]>
Here is the preliminary XZ embedded patch for EROFS from Lasse Collin. Just for archiving only as well. Note that it's *not* a final formal patch and I send it to linux-erofs mailing list only for now.
And the brief outline of our discussion for reference:
EROFS would use raw LZMA format, which means no LZMA/ LZMA2/XZ headers and no LZMA EOPM as well since EROFS records all uncompressed sizes. The initial raw LZMA byte (0x00) will be used to store lc/lp/pb and for later BCJ filters.
Cc Lasse Collin <[email protected]>
[ Currently no Signed-off-by: here. ]
--- include/linux/xz.h | 83 +++++++++++++++++++++++++++++ lib/xz/Kconfig | 4 ++ lib/xz/xz_dec_lzma2.c | 120 ++++++++++++++++++++++++++++++++++++++++++ lib/xz/xz_dec_syms.c | 9 +++- lib/xz/xz_private.h | 3 ++ 5 files changed, 218 insertions(+), 1 deletion(-)
include/linux/xz.h +83 -0
@@ -233,6 +233,89 @@ XZ_EXTERN void xz_dec_reset(struct xz_dec *s);*/ XZ_EXTERN void xz_dec_end(struct xz_dec *s); +/* +* Decompressor for the LZMA variant in EROFS +* +* These functions aren't used or available in preboot code and thus aren't +* marked with XZ_EXTERN. This avoids warnings about static functions that +* are never defined. +*/ +/** +* struct xz_dec_erofs_lzma - Opaque type to hold the EROFS LZMA decoder state +*/ +struct xz_dec_erofs_lzma ; + +/** +* xz_dec_erofs_lzma_alloc() - Allocate memory for the EROFS LZMA decoder +* @dict_size LZMA dictionary size. This must be at least 4 KiB and +* at most 3 GiB. +* +* In contrast to xz_dec_init(), this function only allocates the memory (less +* than 30 KiB) and remembers the dictionary size. xz_dec_erofs_lzma_reset() +* must be used before calling xz_dec_erofs_lzma_run(). +* +* On success, xz_dec_erofs_lzma_alloc() returns a pointer to +* struct xz_dec_erofs_lzma. If memory allocation fails or +* dict_size is invalid, NULL is returned. +*/ +extern struct xz_dec_erofs_lzma *xz_dec_erofs_lzma_alloc (uint32_t dict_size); + +/** +* xz_dec_erofs_lzma_reset() - Reset the EROFS LZMA decoder state +* @s Decoder state allocated using xz_dec_erofs_alloc() +* @uncomp_size Uncompressed size of the input stream +* @comp_size Compressed size of the input stream +*/ +extern void xz_dec_erofs_lzma_reset (struct xz_dec_erofs_lzma *s, +uint32_t uncomp_size,uint32_t comp_size); + +/** +* xz_dec_erofs_lzma_run() - Run the EROFS LZMA decoder +* @s Decoder state initialized using xz_dec_erofs_lzma_reset() +* @b: Input and output buffers +* +* This works the same way as xz_dec_run() in single-call mode (XZ_SINGLE) +* except this may also return XZ_OK. After XZ_OK the bytes decoded so far +* may be read from the output buffer. It is also possible to continue +* decoding but the variables b->out, b->out_pos, and b->out_size MUST NOT +* be changed by the caller. The input buffer may be changed normally (like +* with xz_dec_run() in multi-call mode). This way input data can be provided +* from non-contiguous memory. The output space must still be contiguous +* and it must be provided as a whole on the first call to this function. +* +* It is OK to provide an output buffer smaller than the uncompressed size. +* In this case XZ_BUF_ERROR is returned once the output buffer is full. +* If an undersided output buffer is used intentionally, XZ_BUF_ERROR can +* be treated like XZ_STREAM_END. +* +* If output buffer is at least as big as the specified uncompressed size, +* then XZ_STREAM_END is returned when uncompressed size number of bytes +* have been decoded. +* +* If the compressed data seems to be corrupt, XZ_DATA_ERROR is returned. +* This can happen also when incorrect dictionary, uncompressed, or +* compressed sizes have been specified. +* +* Return values other than XZ_STREAM_END, XZ_BUF_ERROR, XZ_OK, and +* XZ_DATA_ERROR are not possible. +* +* The compressed format supported by this decoder is a raw LZMA stream +* whose first byte (always 0x00) has been replaced with bitwise-negation +* of the the LZMA properties (lc/lp/pb) byte. For example, if lc/lp/pb is +* 3/0/2, the first byte is 0xA2. This way the first byte can never be 0x00. +* Just like with LZMA2, lc + lp <= 4 must be true. The LZMA end-of-stream +* marker must not be used. +*/ +extern enum xz_ret xz_dec_erofs_lzma_run (struct xz_dec_erofs_lzma *s, +struct xz_buf *b); + +/** +* xz_dec_erofs_lzma_end() - Free the memory allocated for the decoder state +* @s: Decoder state allocated using xz_dec_erofs_alloc(). +* If s is NULL, this function does nothing. +*/ +extern void xz_dec_erofs_lzma_end (struct xz_dec_erofs_lzma *s); +/* * Standalone build (userspace build or in-kernel build for boot time use) * needs a CRC32 implementation. For normal in-kernel use, kernel's own
lib/xz/Kconfig +4 -0
@@ -45,6 +45,10 @@ config XZ_DEC_BCJ bool default n +config XZ_DEC_EROFS_LZMA + bool + default n + config XZ_DEC_TEST tristate "XZ decompressor tester" default n
lib/xz/xz_dec_lzma2.c +120 -0
123 lines not on this page · raw message
lib/xz/xz_dec_syms.c +8 -1
@@ -15,8 +15,15 @@ EXPORT_SYMBOL(xz_dec_reset);EXPORT_SYMBOL (xz_dec_run);EXPORT_SYMBOL (xz_dec_end); +#ifdef CONFIG_XZ_DEC_EROFS_LZMA +EXPORT_SYMBOL (xz_dec_erofs_lzma_alloc); +EXPORT_SYMBOL (xz_dec_erofs_lzma_reset); +EXPORT_SYMBOL (xz_dec_erofs_lzma_run); +EXPORT_SYMBOL (xz_dec_erofs_lzma_end); +#endif +MODULE_DESCRIPTION ("XZ decompressor" ); -MODULE_VERSION ("1.0" ); +MODULE_VERSION ("1.1" );MODULE_AUTHOR ("Lasse Collin <[email protected]> and Igor Pavlov" );/*
lib/xz/xz_private.h +3 -0
@@ -37,6 +37,9 @@# ifdef CONFIG_XZ_DEC_SPARC # define XZ_DEC_SPARC # endif +# ifdef CONFIG_XZ_DEC_EROFS_LZMA +# define XZ_DEC_EROFS_LZMA +# endif # define memeq (a, b, size) (memcmp(a, b, size) == 0)# define memzero (buf, size) memset(buf, 0, size)# endif
Signature · 1 line
2.20.1