2 * \file lzma/stream_flags.h
3 * \brief .xz Stream Header and Stream Footer encoder and decoder
4 * \note Never include this file directly. Use <lzma.h> instead.
10 * This file has been put into the public domain.
11 * You can do whatever you want with this file.
14 #ifndef LZMA_H_INTERNAL
15 # error Never include this file directly. Use <lzma.h> instead.
20 * \brief Size of Stream Header and Stream Footer
22 * Stream Header and Stream Footer have the same size and they are not
23 * going to change even if a newer version of the .xz file format is
24 * developed in future.
26 #define LZMA_STREAM_HEADER_SIZE 12
30 * \brief Options for encoding/decoding Stream Header and Stream Footer
34 * \brief Stream Flags format version
36 * To prevent API and ABI breakages if new features are needed in
37 * Stream Header or Stream Footer, a version number is used to
38 * indicate which members in this structure are in use. For now,
39 * version must always be zero. With non-zero version, the
40 * lzma_stream_header_encode() and lzma_stream_footer_encode()
41 * will return LZMA_OPTIONS_ERROR.
43 * lzma_stream_header_decode() and lzma_stream_footer_decode()
44 * will always set this to the lowest value that supports all the
45 * features indicated by the Stream Flags field. The application
46 * must check that the version number set by the decoding functions
47 * is supported by the application. Otherwise it is possible that
48 * the application will decode the Stream incorrectly.
53 * \brief Backward Size
55 * Backward Size must be a multiple of four bytes. In this Stream
56 * format version, Backward Size is the size of the Index field.
58 * Backward Size isn't actually part of the Stream Flags field, but
59 * it is convenient to include in this structure anyway. Backward
60 * Size is present only in the Stream Footer. There is no need to
61 * initialize backward_size when encoding Stream Header.
63 * lzma_stream_header_decode() always sets backward_size to
64 * LZMA_VLI_UNKNOWN so that it is convenient to use
65 * lzma_stream_flags_compare() when both Stream Header and Stream
66 * Footer have been decoded.
68 lzma_vli backward_size
;
71 * \brief Minimum value for lzma_stream_flags.backward_size
73 # define LZMA_BACKWARD_SIZE_MIN 4
76 * \brief Maximum value for lzma_stream_flags.backward_size
78 # define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
83 * This indicates the type of the integrity check calculated from
89 * Reserved space to allow possible future extensions without
90 * breaking the ABI. You should not touch these, because the
91 * names of these variables may change.
93 * (We will never be able to use all of these since Stream Flags
94 * is just two bytes plus Backward Size of four bytes. But it's
95 * nice to have the proper types when they are needed.)
98 /** \private Reserved member. */
99 lzma_reserved_enum reserved_enum1
;
101 /** \private Reserved member. */
102 lzma_reserved_enum reserved_enum2
;
104 /** \private Reserved member. */
105 lzma_reserved_enum reserved_enum3
;
107 /** \private Reserved member. */
108 lzma_reserved_enum reserved_enum4
;
110 /** \private Reserved member. */
111 lzma_bool reserved_bool1
;
113 /** \private Reserved member. */
114 lzma_bool reserved_bool2
;
116 /** \private Reserved member. */
117 lzma_bool reserved_bool3
;
119 /** \private Reserved member. */
120 lzma_bool reserved_bool4
;
122 /** \private Reserved member. */
123 lzma_bool reserved_bool5
;
125 /** \private Reserved member. */
126 lzma_bool reserved_bool6
;
128 /** \private Reserved member. */
129 lzma_bool reserved_bool7
;
131 /** \private Reserved member. */
132 lzma_bool reserved_bool8
;
134 /** \private Reserved member. */
135 uint32_t reserved_int1
;
137 /** \private Reserved member. */
138 uint32_t reserved_int2
;
144 * \brief Encode Stream Header
146 * \param options Stream Header options to be encoded.
147 * options->backward_size is ignored and doesn't
148 * need to be initialized.
149 * \param[out] out Beginning of the output buffer of
150 * LZMA_STREAM_HEADER_SIZE bytes.
152 * \return Possible lzma_ret values:
153 * - LZMA_OK: Encoding was successful.
154 * - LZMA_OPTIONS_ERROR: options->version is not supported by
155 * this liblzma version.
156 * - LZMA_PROG_ERROR: Invalid options.
158 extern LZMA_API(lzma_ret
) lzma_stream_header_encode(
159 const lzma_stream_flags
*options
, uint8_t *out
)
160 lzma_nothrow lzma_attr_warn_unused_result
;
164 * \brief Encode Stream Footer
166 * \param options Stream Footer options to be encoded.
167 * \param[out] out Beginning of the output buffer of
168 * LZMA_STREAM_HEADER_SIZE bytes.
170 * \return Possible lzma_ret values:
171 * - LZMA_OK: Encoding was successful.
172 * - LZMA_OPTIONS_ERROR: options->version is not supported by
173 * this liblzma version.
174 * - LZMA_PROG_ERROR: Invalid options.
176 extern LZMA_API(lzma_ret
) lzma_stream_footer_encode(
177 const lzma_stream_flags
*options
, uint8_t *out
)
178 lzma_nothrow lzma_attr_warn_unused_result
;
182 * \brief Decode Stream Header
184 * options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to
185 * help comparing Stream Flags from Stream Header and Stream Footer with
186 * lzma_stream_flags_compare().
188 * \note When decoding .xz files that contain multiple Streams, it may
189 * make sense to print "file format not recognized" only if
190 * decoding of the Stream Header of the \a first Stream gives
191 * LZMA_FORMAT_ERROR. If non-first Stream Header gives
192 * LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is
193 * probably more appropriate.
194 * For example, the Stream decoder in liblzma uses
195 * LZMA_DATA_ERROR if LZMA_FORMAT_ERROR is returned by
196 * lzma_stream_header_decode() when decoding non-first Stream.
198 * \param[out] options Target for the decoded Stream Header options.
199 * \param in Beginning of the input buffer of
200 * LZMA_STREAM_HEADER_SIZE bytes.
203 * \return Possible lzma_ret values:
204 * - LZMA_OK: Decoding was successful.
205 * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
206 * buffer cannot be Stream Header.
207 * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
209 * - LZMA_OPTIONS_ERROR: Unsupported options are present
212 extern LZMA_API(lzma_ret
) lzma_stream_header_decode(
213 lzma_stream_flags
*options
, const uint8_t *in
)
214 lzma_nothrow lzma_attr_warn_unused_result
;
218 * \brief Decode Stream Footer
220 * \note If Stream Header was already decoded successfully, but
221 * decoding Stream Footer returns LZMA_FORMAT_ERROR, the
222 * application should probably report some other error message
223 * than "file format not recognized". The file likely
224 * is corrupt (possibly truncated). The Stream decoder in liblzma
225 * uses LZMA_DATA_ERROR in this situation.
227 * \param[out] options Target for the decoded Stream Footer options.
228 * \param in Beginning of the input buffer of
229 * LZMA_STREAM_HEADER_SIZE bytes.
231 * \return Possible lzma_ret values:
232 * - LZMA_OK: Decoding was successful.
233 * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
234 * buffer cannot be Stream Footer.
235 * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer
237 * - LZMA_OPTIONS_ERROR: Unsupported options are present
240 extern LZMA_API(lzma_ret
) lzma_stream_footer_decode(
241 lzma_stream_flags
*options
, const uint8_t *in
)
242 lzma_nothrow lzma_attr_warn_unused_result
;
246 * \brief Compare two lzma_stream_flags structures
248 * backward_size values are compared only if both are not
251 * \param a Pointer to lzma_stream_flags structure
252 * \param b Pointer to lzma_stream_flags structure
254 * \return Possible lzma_ret values:
255 * - LZMA_OK: Both are equal. If either had backward_size set
256 * to LZMA_VLI_UNKNOWN, backward_size values were not
257 * compared or validated.
258 * - LZMA_DATA_ERROR: The structures differ.
259 * - LZMA_OPTIONS_ERROR: version in either structure is greater
260 * than the maximum supported version (currently zero).
261 * - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or
264 extern LZMA_API(lzma_ret
) lzma_stream_flags_compare(
265 const lzma_stream_flags
*a
, const lzma_stream_flags
*b
)
266 lzma_nothrow lzma_attr_pure
;