blob: 9da8d7061dd9d4076de163fe03547569685df6a2 [file] [log] [blame]
Denys Vlasenko602ce692010-05-30 03:35:18 +02001/*
2 * Private includes and definitions
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#ifndef XZ_PRIVATE_H
11#define XZ_PRIVATE_H
12
13#ifdef __KERNEL__
14 /* XZ_PREBOOT may be defined only via decompress_unxz.c. */
15# ifndef XZ_PREBOOT
16# include <linux/slab.h>
17# include <linux/vmalloc.h>
18# include <linux/string.h>
19# define memeq(a, b, size) (memcmp(a, b, size) == 0)
20# define memzero(buf, size) memset(buf, 0, size)
21# endif
22# include <asm/byteorder.h>
23# include <asm/unaligned.h>
24# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
25 /* XZ_IGNORE_KCONFIG may be defined only via decompress_unxz.c. */
26# ifndef XZ_IGNORE_KCONFIG
27# ifdef CONFIG_XZ_DEC_X86
28# define XZ_DEC_X86
29# endif
30# ifdef CONFIG_XZ_DEC_POWERPC
31# define XZ_DEC_POWERPC
32# endif
33# ifdef CONFIG_XZ_DEC_IA64
34# define XZ_DEC_IA64
35# endif
36# ifdef CONFIG_XZ_DEC_ARM
37# define XZ_DEC_ARM
38# endif
39# ifdef CONFIG_XZ_DEC_ARMTHUMB
40# define XZ_DEC_ARMTHUMB
41# endif
42# ifdef CONFIG_XZ_DEC_SPARC
43# define XZ_DEC_SPARC
44# endif
45# endif
46# include <linux/xz.h>
47#else
48 /*
49 * For userspace builds, use a separate header to define the required
50 * macros and functions. This makes it easier to adapt the code into
51 * different environments and avoids clutter in the Linux kernel tree.
52 */
53# include "xz_config.h"
54#endif
55
56/*
57 * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
58 * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
59 */
60#ifndef XZ_DEC_BCJ
61# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
62 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
63 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
64 || defined(XZ_DEC_SPARC)
65# define XZ_DEC_BCJ
66# endif
67#endif
68
69/*
70 * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
71 * before calling xz_dec_lzma2_run().
72 */
73XZ_EXTERN struct xz_dec_lzma2 * XZ_FUNC xz_dec_lzma2_create(
74 uint32_t dict_max);
75
76/*
77 * Decode the LZMA2 properties (one byte) and reset the decoder. Return
78 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
79 * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
80 * decoder doesn't support.
81 */
82XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_lzma2_reset(
83 struct xz_dec_lzma2 *s, uint8_t props);
84
85/* Decode raw LZMA2 stream from b->in to b->out. */
86XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_lzma2_run(
87 struct xz_dec_lzma2 *s, struct xz_buf *b);
88
89/* Free the memory allocated for the LZMA2 decoder. */
90XZ_EXTERN void XZ_FUNC xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
91
92#ifdef XZ_DEC_BCJ
93/*
94 * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
95 * calling xz_dec_bcj_run().
96 */
97XZ_EXTERN struct xz_dec_bcj * XZ_FUNC xz_dec_bcj_create(bool single_call);
98
99/*
100 * Decode the Filter ID of a BCJ filter. This implementation doesn't
101 * support custom start offsets, so no decoding of Filter Properties
102 * is needed. Returns XZ_OK if the given Filter ID is supported.
103 * Otherwise XZ_OPTIONS_ERROR is returned.
104 */
105XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_reset(
106 struct xz_dec_bcj *s, uint8_t id);
107
108/*
109 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
110 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
111 * must be called directly.
112 */
113XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
114 struct xz_dec_lzma2 *lzma2, struct xz_buf *b);
115#endif
116
117/* Free the memory allocated for the BCJ filters. */
118#define xz_dec_bcj_end(s) kfree(s)
119
120#endif