xref: /freebsd/contrib/xz/src/liblzma/api/lzma/lzma12.h (revision 73ed8e77a79398eb8e7b600a0b67f286e9e5cd53)
153200025SRui Paulo /**
253200025SRui Paulo  * \file        lzma/lzma12.h
353200025SRui Paulo  * \brief       LZMA1 and LZMA2 filters
453200025SRui Paulo  */
553200025SRui Paulo 
653200025SRui Paulo /*
753200025SRui Paulo  * Author: Lasse Collin
853200025SRui Paulo  *
953200025SRui Paulo  * This file has been put into the public domain.
1053200025SRui Paulo  * You can do whatever you want with this file.
1153200025SRui Paulo  *
1253200025SRui Paulo  * See ../lzma.h for information about liblzma as a whole.
1353200025SRui Paulo  */
1453200025SRui Paulo 
1553200025SRui Paulo #ifndef LZMA_H_INTERNAL
1653200025SRui Paulo #	error Never include this file directly. Use <lzma.h> instead.
1753200025SRui Paulo #endif
1853200025SRui Paulo 
1953200025SRui Paulo 
2053200025SRui Paulo /**
21*73ed8e77SXin LI  * \brief       LZMA1 Filter ID (for raw encoder/decoder only, not in .xz)
2253200025SRui Paulo  *
2353200025SRui Paulo  * LZMA1 is the very same thing as what was called just LZMA in LZMA Utils,
2453200025SRui Paulo  * 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from
2553200025SRui Paulo  * accidentally using LZMA when they actually want LZMA2.
2653200025SRui Paulo  */
2753200025SRui Paulo #define LZMA_FILTER_LZMA1       LZMA_VLI_C(0x4000000000000001)
2853200025SRui Paulo 
2953200025SRui Paulo /**
30*73ed8e77SXin LI  * \brief       LZMA1 Filter ID with extended options (for raw encoder/decoder)
31*73ed8e77SXin LI  *
32*73ed8e77SXin LI  * This is like LZMA_FILTER_LZMA1 but with this ID a few extra options
33*73ed8e77SXin LI  * are supported in the lzma_options_lzma structure:
34*73ed8e77SXin LI  *
35*73ed8e77SXin LI  *   - A flag to tell the encoder if the end of payload marker (EOPM) alias
36*73ed8e77SXin LI  *     end of stream (EOS) marker must be written at the end of the stream.
37*73ed8e77SXin LI  *     In contrast, LZMA_FILTER_LZMA1 always writes the end marker.
38*73ed8e77SXin LI  *
39*73ed8e77SXin LI  *   - Decoder needs to be told the uncompressed size of the stream
40*73ed8e77SXin LI  *     or that it is unknown (using the special value UINT64_MAX).
41*73ed8e77SXin LI  *     If the size is known, a flag can be set to allow the presence of
42*73ed8e77SXin LI  *     the end marker anyway. In contrast, LZMA_FILTER_LZMA1 always
43*73ed8e77SXin LI  *     behaves as if the uncompressed size was unknown.
44*73ed8e77SXin LI  *
45*73ed8e77SXin LI  * This allows handling file formats where LZMA1 streams are used but where
46*73ed8e77SXin LI  * the end marker isn't allowed or where it might not (always) be present.
47*73ed8e77SXin LI  * This extended LZMA1 functionality is provided as a Filter ID for raw
48*73ed8e77SXin LI  * encoder and decoder instead of adding new encoder and decoder initialization
49*73ed8e77SXin LI  * functions because this way it is possible to also use extra filters,
50*73ed8e77SXin LI  * for example, LZMA_FILTER_X86 in a filter chain with LZMA_FILTER_LZMA1EXT,
51*73ed8e77SXin LI  * which might be needed to handle some file formats.
52*73ed8e77SXin LI  */
53*73ed8e77SXin LI #define LZMA_FILTER_LZMA1EXT    LZMA_VLI_C(0x4000000000000002)
54*73ed8e77SXin LI 
55*73ed8e77SXin LI /**
5653200025SRui Paulo  * \brief       LZMA2 Filter ID
5753200025SRui Paulo  *
5853200025SRui Paulo  * Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds
5953200025SRui Paulo  * support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion
6053200025SRui Paulo  * when trying to compress uncompressible data), possibility to change
6153200025SRui Paulo  * lc/lp/pb in the middle of encoding, and some other internal improvements.
6253200025SRui Paulo  */
6353200025SRui Paulo #define LZMA_FILTER_LZMA2       LZMA_VLI_C(0x21)
6453200025SRui Paulo 
6553200025SRui Paulo 
6653200025SRui Paulo /**
6753200025SRui Paulo  * \brief       Match finders
6853200025SRui Paulo  *
6953200025SRui Paulo  * Match finder has major effect on both speed and compression ratio.
7053200025SRui Paulo  * Usually hash chains are faster than binary trees.
7153200025SRui Paulo  *
7253200025SRui Paulo  * If you will use LZMA_SYNC_FLUSH often, the hash chains may be a better
7353200025SRui Paulo  * choice, because binary trees get much higher compression ratio penalty
7453200025SRui Paulo  * with LZMA_SYNC_FLUSH.
7553200025SRui Paulo  *
7653200025SRui Paulo  * The memory usage formulas are only rough estimates, which are closest to
7753200025SRui Paulo  * reality when dict_size is a power of two. The formulas are  more complex
7853200025SRui Paulo  * in reality, and can also change a little between liblzma versions. Use
7953200025SRui Paulo  * lzma_raw_encoder_memusage() to get more accurate estimate of memory usage.
8053200025SRui Paulo  */
8153200025SRui Paulo typedef enum {
8253200025SRui Paulo 	LZMA_MF_HC3     = 0x03,
8353200025SRui Paulo 		/**<
8453200025SRui Paulo 		 * \brief       Hash Chain with 2- and 3-byte hashing
8553200025SRui Paulo 		 *
8653200025SRui Paulo 		 * Minimum nice_len: 3
8753200025SRui Paulo 		 *
8853200025SRui Paulo 		 * Memory usage:
8953200025SRui Paulo 		 *  - dict_size <= 16 MiB: dict_size * 7.5
9053200025SRui Paulo 		 *  - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB
9153200025SRui Paulo 		 */
9253200025SRui Paulo 
9353200025SRui Paulo 	LZMA_MF_HC4     = 0x04,
9453200025SRui Paulo 		/**<
9553200025SRui Paulo 		 * \brief       Hash Chain with 2-, 3-, and 4-byte hashing
9653200025SRui Paulo 		 *
9753200025SRui Paulo 		 * Minimum nice_len: 4
9853200025SRui Paulo 		 *
9953200025SRui Paulo 		 * Memory usage:
10053200025SRui Paulo 		 *  - dict_size <= 32 MiB: dict_size * 7.5
10153200025SRui Paulo 		 *  - dict_size > 32 MiB: dict_size * 6.5
10253200025SRui Paulo 		 */
10353200025SRui Paulo 
10453200025SRui Paulo 	LZMA_MF_BT2     = 0x12,
10553200025SRui Paulo 		/**<
10653200025SRui Paulo 		 * \brief       Binary Tree with 2-byte hashing
10753200025SRui Paulo 		 *
10853200025SRui Paulo 		 * Minimum nice_len: 2
10953200025SRui Paulo 		 *
11053200025SRui Paulo 		 * Memory usage: dict_size * 9.5
11153200025SRui Paulo 		 */
11253200025SRui Paulo 
11353200025SRui Paulo 	LZMA_MF_BT3     = 0x13,
11453200025SRui Paulo 		/**<
11553200025SRui Paulo 		 * \brief       Binary Tree with 2- and 3-byte hashing
11653200025SRui Paulo 		 *
11753200025SRui Paulo 		 * Minimum nice_len: 3
11853200025SRui Paulo 		 *
11953200025SRui Paulo 		 * Memory usage:
12053200025SRui Paulo 		 *  - dict_size <= 16 MiB: dict_size * 11.5
12153200025SRui Paulo 		 *  - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB
12253200025SRui Paulo 		 */
12353200025SRui Paulo 
12453200025SRui Paulo 	LZMA_MF_BT4     = 0x14
12553200025SRui Paulo 		/**<
12653200025SRui Paulo 		 * \brief       Binary Tree with 2-, 3-, and 4-byte hashing
12753200025SRui Paulo 		 *
12853200025SRui Paulo 		 * Minimum nice_len: 4
12953200025SRui Paulo 		 *
13053200025SRui Paulo 		 * Memory usage:
13153200025SRui Paulo 		 *  - dict_size <= 32 MiB: dict_size * 11.5
13253200025SRui Paulo 		 *  - dict_size > 32 MiB: dict_size * 10.5
13353200025SRui Paulo 		 */
13453200025SRui Paulo } lzma_match_finder;
13553200025SRui Paulo 
13653200025SRui Paulo 
13753200025SRui Paulo /**
13853200025SRui Paulo  * \brief       Test if given match finder is supported
13953200025SRui Paulo  *
14053200025SRui Paulo  * Return true if the given match finder is supported by this liblzma build.
14153200025SRui Paulo  * Otherwise false is returned. It is safe to call this with a value that
14253200025SRui Paulo  * isn't listed in lzma_match_finder enumeration; the return value will be
14353200025SRui Paulo  * false.
14453200025SRui Paulo  *
14553200025SRui Paulo  * There is no way to list which match finders are available in this
14653200025SRui Paulo  * particular liblzma version and build. It would be useless, because
14753200025SRui Paulo  * a new match finder, which the application developer wasn't aware,
14853200025SRui Paulo  * could require giving additional options to the encoder that the older
14953200025SRui Paulo  * match finders don't need.
15053200025SRui Paulo  */
15153200025SRui Paulo extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder)
15253200025SRui Paulo 		lzma_nothrow lzma_attr_const;
15353200025SRui Paulo 
15453200025SRui Paulo 
15553200025SRui Paulo /**
15653200025SRui Paulo  * \brief       Compression modes
15753200025SRui Paulo  *
15853200025SRui Paulo  * This selects the function used to analyze the data produced by the match
15953200025SRui Paulo  * finder.
16053200025SRui Paulo  */
16153200025SRui Paulo typedef enum {
16253200025SRui Paulo 	LZMA_MODE_FAST = 1,
16353200025SRui Paulo 		/**<
16453200025SRui Paulo 		 * \brief       Fast compression
16553200025SRui Paulo 		 *
16653200025SRui Paulo 		 * Fast mode is usually at its best when combined with
16753200025SRui Paulo 		 * a hash chain match finder.
16853200025SRui Paulo 		 */
16953200025SRui Paulo 
17053200025SRui Paulo 	LZMA_MODE_NORMAL = 2
17153200025SRui Paulo 		/**<
17253200025SRui Paulo 		 * \brief       Normal compression
17353200025SRui Paulo 		 *
17453200025SRui Paulo 		 * This is usually notably slower than fast mode. Use this
17553200025SRui Paulo 		 * together with binary tree match finders to expose the
17653200025SRui Paulo 		 * full potential of the LZMA1 or LZMA2 encoder.
17753200025SRui Paulo 		 */
17853200025SRui Paulo } lzma_mode;
17953200025SRui Paulo 
18053200025SRui Paulo 
18153200025SRui Paulo /**
18253200025SRui Paulo  * \brief       Test if given compression mode is supported
18353200025SRui Paulo  *
18453200025SRui Paulo  * Return true if the given compression mode is supported by this liblzma
18553200025SRui Paulo  * build. Otherwise false is returned. It is safe to call this with a value
18653200025SRui Paulo  * that isn't listed in lzma_mode enumeration; the return value will be false.
18753200025SRui Paulo  *
18853200025SRui Paulo  * There is no way to list which modes are available in this particular
18953200025SRui Paulo  * liblzma version and build. It would be useless, because a new compression
19053200025SRui Paulo  * mode, which the application developer wasn't aware, could require giving
19153200025SRui Paulo  * additional options to the encoder that the older modes don't need.
19253200025SRui Paulo  */
19353200025SRui Paulo extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode)
19453200025SRui Paulo 		lzma_nothrow lzma_attr_const;
19553200025SRui Paulo 
19653200025SRui Paulo 
19753200025SRui Paulo /**
19853200025SRui Paulo  * \brief       Options specific to the LZMA1 and LZMA2 filters
19953200025SRui Paulo  *
20053200025SRui Paulo  * Since LZMA1 and LZMA2 share most of the code, it's simplest to share
20153200025SRui Paulo  * the options structure too. For encoding, all but the reserved variables
20253200025SRui Paulo  * need to be initialized unless specifically mentioned otherwise.
20353200025SRui Paulo  * lzma_lzma_preset() can be used to get a good starting point.
20453200025SRui Paulo  *
20553200025SRui Paulo  * For raw decoding, both LZMA1 and LZMA2 need dict_size, preset_dict, and
20653200025SRui Paulo  * preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb.
20753200025SRui Paulo  */
20853200025SRui Paulo typedef struct {
20953200025SRui Paulo 	/**
21053200025SRui Paulo 	 * \brief       Dictionary size in bytes
21153200025SRui Paulo 	 *
21253200025SRui Paulo 	 * Dictionary size indicates how many bytes of the recently processed
21353200025SRui Paulo 	 * uncompressed data is kept in memory. One method to reduce size of
21453200025SRui Paulo 	 * the uncompressed data is to store distance-length pairs, which
21553200025SRui Paulo 	 * indicate what data to repeat from the dictionary buffer. Thus,
21653200025SRui Paulo 	 * the bigger the dictionary, the better the compression ratio
21753200025SRui Paulo 	 * usually is.
21853200025SRui Paulo 	 *
21953200025SRui Paulo 	 * Maximum size of the dictionary depends on multiple things:
22053200025SRui Paulo 	 *  - Memory usage limit
22153200025SRui Paulo 	 *  - Available address space (not a problem on 64-bit systems)
22253200025SRui Paulo 	 *  - Selected match finder (encoder only)
22353200025SRui Paulo 	 *
22453200025SRui Paulo 	 * Currently the maximum dictionary size for encoding is 1.5 GiB
22553200025SRui Paulo 	 * (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit
22653200025SRui Paulo 	 * systems for certain match finder implementation reasons. In the
22753200025SRui Paulo 	 * future, there may be match finders that support bigger
22853200025SRui Paulo 	 * dictionaries.
22953200025SRui Paulo 	 *
23053200025SRui Paulo 	 * Decoder already supports dictionaries up to 4 GiB - 1 B (i.e.
23153200025SRui Paulo 	 * UINT32_MAX), so increasing the maximum dictionary size of the
23253200025SRui Paulo 	 * encoder won't cause problems for old decoders.
23353200025SRui Paulo 	 *
23453200025SRui Paulo 	 * Because extremely small dictionaries sizes would have unneeded
23553200025SRui Paulo 	 * overhead in the decoder, the minimum dictionary size is 4096 bytes.
23653200025SRui Paulo 	 *
23753200025SRui Paulo 	 * \note        When decoding, too big dictionary does no other harm
23853200025SRui Paulo 	 *              than wasting memory.
23953200025SRui Paulo 	 */
24053200025SRui Paulo 	uint32_t dict_size;
24153200025SRui Paulo #	define LZMA_DICT_SIZE_MIN       UINT32_C(4096)
24253200025SRui Paulo #	define LZMA_DICT_SIZE_DEFAULT   (UINT32_C(1) << 23)
24353200025SRui Paulo 
24453200025SRui Paulo 	/**
24553200025SRui Paulo 	 * \brief       Pointer to an initial dictionary
24653200025SRui Paulo 	 *
24753200025SRui Paulo 	 * It is possible to initialize the LZ77 history window using
24853200025SRui Paulo 	 * a preset dictionary. It is useful when compressing many
24953200025SRui Paulo 	 * similar, relatively small chunks of data independently from
25053200025SRui Paulo 	 * each other. The preset dictionary should contain typical
25153200025SRui Paulo 	 * strings that occur in the files being compressed. The most
25253200025SRui Paulo 	 * probable strings should be near the end of the preset dictionary.
25353200025SRui Paulo 	 *
25453200025SRui Paulo 	 * This feature should be used only in special situations. For
25553200025SRui Paulo 	 * now, it works correctly only with raw encoding and decoding.
25653200025SRui Paulo 	 * Currently none of the container formats supported by
25753200025SRui Paulo 	 * liblzma allow preset dictionary when decoding, thus if
25853200025SRui Paulo 	 * you create a .xz or .lzma file with preset dictionary, it
25953200025SRui Paulo 	 * cannot be decoded with the regular decoder functions. In the
26053200025SRui Paulo 	 * future, the .xz format will likely get support for preset
26153200025SRui Paulo 	 * dictionary though.
26253200025SRui Paulo 	 */
26353200025SRui Paulo 	const uint8_t *preset_dict;
26453200025SRui Paulo 
26553200025SRui Paulo 	/**
26653200025SRui Paulo 	 * \brief       Size of the preset dictionary
26753200025SRui Paulo 	 *
26853200025SRui Paulo 	 * Specifies the size of the preset dictionary. If the size is
26953200025SRui Paulo 	 * bigger than dict_size, only the last dict_size bytes are
27053200025SRui Paulo 	 * processed.
27153200025SRui Paulo 	 *
27253200025SRui Paulo 	 * This variable is read only when preset_dict is not NULL.
27353200025SRui Paulo 	 * If preset_dict is not NULL but preset_dict_size is zero,
27453200025SRui Paulo 	 * no preset dictionary is used (identical to only setting
27553200025SRui Paulo 	 * preset_dict to NULL).
27653200025SRui Paulo 	 */
27753200025SRui Paulo 	uint32_t preset_dict_size;
27853200025SRui Paulo 
27953200025SRui Paulo 	/**
28053200025SRui Paulo 	 * \brief       Number of literal context bits
28153200025SRui Paulo 	 *
28253200025SRui Paulo 	 * How many of the highest bits of the previous uncompressed
28353200025SRui Paulo 	 * eight-bit byte (also known as `literal') are taken into
28453200025SRui Paulo 	 * account when predicting the bits of the next literal.
28553200025SRui Paulo 	 *
28653200025SRui Paulo 	 * E.g. in typical English text, an upper-case letter is
28753200025SRui Paulo 	 * often followed by a lower-case letter, and a lower-case
28853200025SRui Paulo 	 * letter is usually followed by another lower-case letter.
28953200025SRui Paulo 	 * In the US-ASCII character set, the highest three bits are 010
29053200025SRui Paulo 	 * for upper-case letters and 011 for lower-case letters.
29153200025SRui Paulo 	 * When lc is at least 3, the literal coding can take advantage of
29253200025SRui Paulo 	 * this property in the uncompressed data.
29353200025SRui Paulo 	 *
29453200025SRui Paulo 	 * There is a limit that applies to literal context bits and literal
29553200025SRui Paulo 	 * position bits together: lc + lp <= 4. Without this limit the
29653200025SRui Paulo 	 * decoding could become very slow, which could have security related
29753200025SRui Paulo 	 * results in some cases like email servers doing virus scanning.
29853200025SRui Paulo 	 * This limit also simplifies the internal implementation in liblzma.
29953200025SRui Paulo 	 *
30053200025SRui Paulo 	 * There may be LZMA1 streams that have lc + lp > 4 (maximum possible
30153200025SRui Paulo 	 * lc would be 8). It is not possible to decode such streams with
30253200025SRui Paulo 	 * liblzma.
30353200025SRui Paulo 	 */
30453200025SRui Paulo 	uint32_t lc;
30553200025SRui Paulo #	define LZMA_LCLP_MIN    0
30653200025SRui Paulo #	define LZMA_LCLP_MAX    4
30753200025SRui Paulo #	define LZMA_LC_DEFAULT  3
30853200025SRui Paulo 
30953200025SRui Paulo 	/**
31053200025SRui Paulo 	 * \brief       Number of literal position bits
31153200025SRui Paulo 	 *
31253200025SRui Paulo 	 * lp affects what kind of alignment in the uncompressed data is
31353200025SRui Paulo 	 * assumed when encoding literals. A literal is a single 8-bit byte.
31453200025SRui Paulo 	 * See pb below for more information about alignment.
31553200025SRui Paulo 	 */
31653200025SRui Paulo 	uint32_t lp;
31753200025SRui Paulo #	define LZMA_LP_DEFAULT  0
31853200025SRui Paulo 
31953200025SRui Paulo 	/**
32053200025SRui Paulo 	 * \brief       Number of position bits
32153200025SRui Paulo 	 *
32253200025SRui Paulo 	 * pb affects what kind of alignment in the uncompressed data is
32353200025SRui Paulo 	 * assumed in general. The default means four-byte alignment
32453200025SRui Paulo 	 * (2^ pb =2^2=4), which is often a good choice when there's
32553200025SRui Paulo 	 * no better guess.
32653200025SRui Paulo 	 *
327a8675d92SXin LI 	 * When the alignment is known, setting pb accordingly may reduce
32853200025SRui Paulo 	 * the file size a little. E.g. with text files having one-byte
32953200025SRui Paulo 	 * alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can
33053200025SRui Paulo 	 * improve compression slightly. For UTF-16 text, pb=1 is a good
33153200025SRui Paulo 	 * choice. If the alignment is an odd number like 3 bytes, pb=0
33253200025SRui Paulo 	 * might be the best choice.
33353200025SRui Paulo 	 *
33453200025SRui Paulo 	 * Even though the assumed alignment can be adjusted with pb and
33553200025SRui Paulo 	 * lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment.
33653200025SRui Paulo 	 * It might be worth taking into account when designing file formats
33753200025SRui Paulo 	 * that are likely to be often compressed with LZMA1 or LZMA2.
33853200025SRui Paulo 	 */
33953200025SRui Paulo 	uint32_t pb;
34053200025SRui Paulo #	define LZMA_PB_MIN      0
34153200025SRui Paulo #	define LZMA_PB_MAX      4
34253200025SRui Paulo #	define LZMA_PB_DEFAULT  2
34353200025SRui Paulo 
34453200025SRui Paulo 	/** Compression mode */
34553200025SRui Paulo 	lzma_mode mode;
34653200025SRui Paulo 
34753200025SRui Paulo 	/**
34853200025SRui Paulo 	 * \brief       Nice length of a match
34953200025SRui Paulo 	 *
35053200025SRui Paulo 	 * This determines how many bytes the encoder compares from the match
35153200025SRui Paulo 	 * candidates when looking for the best match. Once a match of at
35253200025SRui Paulo 	 * least nice_len bytes long is found, the encoder stops looking for
35353200025SRui Paulo 	 * better candidates and encodes the match. (Naturally, if the found
35453200025SRui Paulo 	 * match is actually longer than nice_len, the actual length is
35553200025SRui Paulo 	 * encoded; it's not truncated to nice_len.)
35653200025SRui Paulo 	 *
35753200025SRui Paulo 	 * Bigger values usually increase the compression ratio and
35853200025SRui Paulo 	 * compression time. For most files, 32 to 128 is a good value,
35953200025SRui Paulo 	 * which gives very good compression ratio at good speed.
36053200025SRui Paulo 	 *
36153200025SRui Paulo 	 * The exact minimum value depends on the match finder. The maximum
36253200025SRui Paulo 	 * is 273, which is the maximum length of a match that LZMA1 and
36353200025SRui Paulo 	 * LZMA2 can encode.
36453200025SRui Paulo 	 */
36553200025SRui Paulo 	uint32_t nice_len;
36653200025SRui Paulo 
36753200025SRui Paulo 	/** Match finder ID */
36853200025SRui Paulo 	lzma_match_finder mf;
36953200025SRui Paulo 
37053200025SRui Paulo 	/**
37153200025SRui Paulo 	 * \brief       Maximum search depth in the match finder
37253200025SRui Paulo 	 *
37353200025SRui Paulo 	 * For every input byte, match finder searches through the hash chain
37453200025SRui Paulo 	 * or binary tree in a loop, each iteration going one step deeper in
37553200025SRui Paulo 	 * the chain or tree. The searching stops if
37653200025SRui Paulo 	 *  - a match of at least nice_len bytes long is found;
37753200025SRui Paulo 	 *  - all match candidates from the hash chain or binary tree have
37853200025SRui Paulo 	 *    been checked; or
37953200025SRui Paulo 	 *  - maximum search depth is reached.
38053200025SRui Paulo 	 *
38153200025SRui Paulo 	 * Maximum search depth is needed to prevent the match finder from
38253200025SRui Paulo 	 * wasting too much time in case there are lots of short match
38353200025SRui Paulo 	 * candidates. On the other hand, stopping the search before all
38453200025SRui Paulo 	 * candidates have been checked can reduce compression ratio.
38553200025SRui Paulo 	 *
38653200025SRui Paulo 	 * Setting depth to zero tells liblzma to use an automatic default
38753200025SRui Paulo 	 * value, that depends on the selected match finder and nice_len.
38853200025SRui Paulo 	 * The default is in the range [4, 200] or so (it may vary between
38953200025SRui Paulo 	 * liblzma versions).
39053200025SRui Paulo 	 *
39153200025SRui Paulo 	 * Using a bigger depth value than the default can increase
39253200025SRui Paulo 	 * compression ratio in some cases. There is no strict maximum value,
39353200025SRui Paulo 	 * but high values (thousands or millions) should be used with care:
39453200025SRui Paulo 	 * the encoder could remain fast enough with typical input, but
39553200025SRui Paulo 	 * malicious input could cause the match finder to slow down
39653200025SRui Paulo 	 * dramatically, possibly creating a denial of service attack.
39753200025SRui Paulo 	 */
39853200025SRui Paulo 	uint32_t depth;
39953200025SRui Paulo 
400*73ed8e77SXin LI 	/**
401*73ed8e77SXin LI 	 * \brief       For LZMA_FILTER_LZMA1EXT: Extended flags
402*73ed8e77SXin LI 	 *
403*73ed8e77SXin LI 	 * This is used only with LZMA_FILTER_LZMA1EXT.
404*73ed8e77SXin LI 	 *
405*73ed8e77SXin LI 	 * Currently only one flag is supported, LZMA_LZMA1EXT_ALLOW_EOPM:
406*73ed8e77SXin LI 	 *
407*73ed8e77SXin LI 	 *   - Encoder: If the flag is set, then end marker is written just
408*73ed8e77SXin LI 	 *     like it is with LZMA_FILTER_LZMA1. Without this flag the
409*73ed8e77SXin LI 	 *     end marker isn't written and the application has to store
410*73ed8e77SXin LI 	 *     the uncompressed size somewhere outside the compressed stream.
411*73ed8e77SXin LI 	 *     To decompress streams without the end marker, the appliation
412*73ed8e77SXin LI 	 *     has to set the correct uncompressed size in ext_size_low and
413*73ed8e77SXin LI 	 *     ext_size_high.
414*73ed8e77SXin LI 	 *
415*73ed8e77SXin LI 	 *   - Decoder: If the uncompressed size in ext_size_low and
416*73ed8e77SXin LI 	 *     ext_size_high is set to the special value UINT64_MAX
417*73ed8e77SXin LI 	 *     (indicating unknown uncompressed size) then this flag is
418*73ed8e77SXin LI 	 *     ignored and the end marker must always be present, that is,
419*73ed8e77SXin LI 	 *     the behavior is identical to LZMA_FILTER_LZMA1.
420*73ed8e77SXin LI 	 *
421*73ed8e77SXin LI 	 *     Otherwise, if this flag isn't set, then the input stream
422*73ed8e77SXin LI 	 *     must not have the end marker; if the end marker is detected
423*73ed8e77SXin LI 	 *     then it will result in LZMA_DATA_ERROR. This is useful when
424*73ed8e77SXin LI 	 *     it is known that the stream must not have the end marker and
425*73ed8e77SXin LI 	 *     strict validation is wanted.
426*73ed8e77SXin LI 	 *
427*73ed8e77SXin LI 	 *     If this flag is set, then it is autodetected if the end marker
428*73ed8e77SXin LI 	 *     is present after the specified number of uncompressed bytes
429*73ed8e77SXin LI 	 *     has been decompressed (ext_size_low and ext_size_high). The
430*73ed8e77SXin LI 	 *     end marker isn't allowed in any other position. This behavior
431*73ed8e77SXin LI 	 *     is useful when uncompressed size is known but the end marker
432*73ed8e77SXin LI 	 *     may or may not be present. This is the case, for example,
433*73ed8e77SXin LI 	 *     in .7z files (valid .7z files that have the end marker in
434*73ed8e77SXin LI 	 *     LZMA1 streams are rare but they do exist).
435*73ed8e77SXin LI 	 */
436*73ed8e77SXin LI 	uint32_t ext_flags;
437*73ed8e77SXin LI #	define LZMA_LZMA1EXT_ALLOW_EOPM   UINT32_C(0x01)
438*73ed8e77SXin LI 
439*73ed8e77SXin LI 	/**
440*73ed8e77SXin LI 	 * \brief       For LZMA_FILTER_LZMA1EXT: Uncompressed size (low bits)
441*73ed8e77SXin LI 	 *
442*73ed8e77SXin LI 	 * The 64-bit uncompressed size is needed for decompression with
443*73ed8e77SXin LI 	 * LZMA_FILTER_LZMA1EXT. The size is ignored by the encoder.
444*73ed8e77SXin LI 	 *
445*73ed8e77SXin LI 	 * The special value UINT64_MAX indicates that the uncompressed size
446*73ed8e77SXin LI 	 * is unknown and that the end of payload marker (also known as
447*73ed8e77SXin LI 	 * end of stream marker) must be present to indicate the end of
448*73ed8e77SXin LI 	 * the LZMA1 stream. Any other value indicates the expected
449*73ed8e77SXin LI 	 * uncompressed size of the LZMA1 stream. (If LZMA1 was used together
450*73ed8e77SXin LI 	 * with filters that change the size of the data then the uncompressed
451*73ed8e77SXin LI 	 * size of the LZMA1 stream could be different than the final
452*73ed8e77SXin LI 	 * uncompressed size of the filtered stream.)
453*73ed8e77SXin LI 	 *
454*73ed8e77SXin LI 	 * ext_size_low holds the least significant 32 bits of the
455*73ed8e77SXin LI 	 * uncompressed size. The most significant 32 bits must be set
456*73ed8e77SXin LI 	 * in ext_size_high. The macro lzma_ext_size_set(opt_lzma, u64size)
457*73ed8e77SXin LI 	 * can be used to set these members.
458*73ed8e77SXin LI 	 *
459*73ed8e77SXin LI 	 * The 64-bit uncompressed size is split into two uint32_t variables
460*73ed8e77SXin LI 	 * because there were no reserved uint64_t members and using the
461*73ed8e77SXin LI 	 * same options structure for LZMA_FILTER_LZMA1, LZMA_FILTER_LZMA1EXT,
462*73ed8e77SXin LI 	 * and LZMA_FILTER_LZMA2 was otherwise more convenient than having
463*73ed8e77SXin LI 	 * a new options structure for LZMA_FILTER_LZMA1EXT. (Replacing two
464*73ed8e77SXin LI 	 * uint32_t members with one uint64_t changes the ABI on some systems
465*73ed8e77SXin LI 	 * as the alignment of this struct can increase from 4 bytes to 8.)
466*73ed8e77SXin LI 	 */
467*73ed8e77SXin LI 	uint32_t ext_size_low;
468*73ed8e77SXin LI 
469*73ed8e77SXin LI 	/**
470*73ed8e77SXin LI 	 * \brief       For LZMA_FILTER_LZMA1EXT: Uncompressed size (high bits)
471*73ed8e77SXin LI 	 *
472*73ed8e77SXin LI 	 * This holds the most significant 32 bits of the uncompressed size.
473*73ed8e77SXin LI 	 */
474*73ed8e77SXin LI 	uint32_t ext_size_high;
475*73ed8e77SXin LI 
47653200025SRui Paulo 	/*
47753200025SRui Paulo 	 * Reserved space to allow possible future extensions without
47853200025SRui Paulo 	 * breaking the ABI. You should not touch these, because the names
47953200025SRui Paulo 	 * of these variables may change. These are and will never be used
48053200025SRui Paulo 	 * with the currently supported options, so it is safe to leave these
48153200025SRui Paulo 	 * uninitialized.
48253200025SRui Paulo 	 */
48353200025SRui Paulo 	uint32_t reserved_int4;
48453200025SRui Paulo 	uint32_t reserved_int5;
48553200025SRui Paulo 	uint32_t reserved_int6;
48653200025SRui Paulo 	uint32_t reserved_int7;
48753200025SRui Paulo 	uint32_t reserved_int8;
48853200025SRui Paulo 	lzma_reserved_enum reserved_enum1;
48953200025SRui Paulo 	lzma_reserved_enum reserved_enum2;
49053200025SRui Paulo 	lzma_reserved_enum reserved_enum3;
49153200025SRui Paulo 	lzma_reserved_enum reserved_enum4;
49253200025SRui Paulo 	void *reserved_ptr1;
49353200025SRui Paulo 	void *reserved_ptr2;
49453200025SRui Paulo 
49553200025SRui Paulo } lzma_options_lzma;
49653200025SRui Paulo 
49753200025SRui Paulo 
49853200025SRui Paulo /**
499*73ed8e77SXin LI  * \brief       Macro to set the 64-bit uncompressed size in ext_size_*
500*73ed8e77SXin LI  *
501*73ed8e77SXin LI  * This might be convenient when decoding using LZMA_FILTER_LZMA1EXT.
502*73ed8e77SXin LI  * This isn't used with LZMA_FILTER_LZMA1 or LZMA_FILTER_LZMA2.
503*73ed8e77SXin LI  */
504*73ed8e77SXin LI #define lzma_set_ext_size(opt_lzma2, u64size) \
505*73ed8e77SXin LI do { \
506*73ed8e77SXin LI 	(opt_lzma2).ext_size_low = (uint32_t)(u64size); \
507*73ed8e77SXin LI 	(opt_lzma2).ext_size_high = (uint32_t)((uint64_t)(u64size) >> 32); \
508*73ed8e77SXin LI } while (0)
509*73ed8e77SXin LI 
510*73ed8e77SXin LI 
511*73ed8e77SXin LI /**
51253200025SRui Paulo  * \brief       Set a compression preset to lzma_options_lzma structure
51353200025SRui Paulo  *
51453200025SRui Paulo  * 0 is the fastest and 9 is the slowest. These match the switches -0 .. -9
51553200025SRui Paulo  * of the xz command line tool. In addition, it is possible to bitwise-or
51653200025SRui Paulo  * flags to the preset. Currently only LZMA_PRESET_EXTREME is supported.
51753200025SRui Paulo  * The flags are defined in container.h, because the flags are used also
51853200025SRui Paulo  * with lzma_easy_encoder().
51953200025SRui Paulo  *
52053200025SRui Paulo  * The preset values are subject to changes between liblzma versions.
52153200025SRui Paulo  *
52253200025SRui Paulo  * This function is available only if LZMA1 or LZMA2 encoder has been enabled
52353200025SRui Paulo  * when building liblzma.
52453200025SRui Paulo  *
52553200025SRui Paulo  * \return      On success, false is returned. If the preset is not
52653200025SRui Paulo  *              supported, true is returned.
52753200025SRui Paulo  */
52853200025SRui Paulo extern LZMA_API(lzma_bool) lzma_lzma_preset(
52953200025SRui Paulo 		lzma_options_lzma *options, uint32_t preset) lzma_nothrow;
530