186d7f5d3SJohn Marino /** 286d7f5d3SJohn Marino * \file lzma/stream_flags.h 386d7f5d3SJohn Marino * \brief .xz Stream Header and Stream Footer encoder and decoder 486d7f5d3SJohn Marino */ 586d7f5d3SJohn Marino 686d7f5d3SJohn Marino /* 786d7f5d3SJohn Marino * Author: Lasse Collin 886d7f5d3SJohn Marino * 986d7f5d3SJohn Marino * This file has been put into the public domain. 1086d7f5d3SJohn Marino * You can do whatever you want with this file. 1186d7f5d3SJohn Marino * 1286d7f5d3SJohn Marino * See ../lzma.h for information about liblzma as a whole. 1386d7f5d3SJohn Marino */ 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marino #ifndef LZMA_H_INTERNAL 1686d7f5d3SJohn Marino # error Never include this file directly. Use <lzma.h> instead. 1786d7f5d3SJohn Marino #endif 1886d7f5d3SJohn Marino 1986d7f5d3SJohn Marino 2086d7f5d3SJohn Marino /** 2186d7f5d3SJohn Marino * \brief Size of Stream Header and Stream Footer 2286d7f5d3SJohn Marino * 2386d7f5d3SJohn Marino * Stream Header and Stream Footer have the same size and they are not 2486d7f5d3SJohn Marino * going to change even if a newer version of the .xz file format is 2586d7f5d3SJohn Marino * developed in future. 2686d7f5d3SJohn Marino */ 2786d7f5d3SJohn Marino #define LZMA_STREAM_HEADER_SIZE 12 2886d7f5d3SJohn Marino 2986d7f5d3SJohn Marino 3086d7f5d3SJohn Marino /** 3186d7f5d3SJohn Marino * \brief Options for encoding/decoding Stream Header and Stream Footer 3286d7f5d3SJohn Marino */ 3386d7f5d3SJohn Marino typedef struct { 3486d7f5d3SJohn Marino /** 3586d7f5d3SJohn Marino * \brief Stream Flags format version 3686d7f5d3SJohn Marino * 3786d7f5d3SJohn Marino * To prevent API and ABI breakages if new features are needed in 3886d7f5d3SJohn Marino * Stream Header or Stream Footer, a version number is used to 3986d7f5d3SJohn Marino * indicate which fields in this structure are in use. For now, 4086d7f5d3SJohn Marino * version must always be zero. With non-zero version, the 4186d7f5d3SJohn Marino * lzma_stream_header_encode() and lzma_stream_footer_encode() 4286d7f5d3SJohn Marino * will return LZMA_OPTIONS_ERROR. 4386d7f5d3SJohn Marino * 4486d7f5d3SJohn Marino * lzma_stream_header_decode() and lzma_stream_footer_decode() 4586d7f5d3SJohn Marino * will always set this to the lowest value that supports all the 4686d7f5d3SJohn Marino * features indicated by the Stream Flags field. The application 4786d7f5d3SJohn Marino * must check that the version number set by the decoding functions 4886d7f5d3SJohn Marino * is supported by the application. Otherwise it is possible that 4986d7f5d3SJohn Marino * the application will decode the Stream incorrectly. 5086d7f5d3SJohn Marino */ 5186d7f5d3SJohn Marino uint32_t version; 5286d7f5d3SJohn Marino 5386d7f5d3SJohn Marino /** 5486d7f5d3SJohn Marino * \brief Backward Size 5586d7f5d3SJohn Marino * 5686d7f5d3SJohn Marino * Backward Size must be a multiple of four bytes. In this Stream 5786d7f5d3SJohn Marino * format version, Backward Size is the size of the Index field. 5886d7f5d3SJohn Marino * 5986d7f5d3SJohn Marino * Backward Size isn't actually part of the Stream Flags field, but 6086d7f5d3SJohn Marino * it is convenient to include in this structure anyway. Backward 6186d7f5d3SJohn Marino * Size is present only in the Stream Footer. There is no need to 6286d7f5d3SJohn Marino * initialize backward_size when encoding Stream Header. 6386d7f5d3SJohn Marino * 6486d7f5d3SJohn Marino * lzma_stream_header_decode() always sets backward_size to 6586d7f5d3SJohn Marino * LZMA_VLI_UNKNOWN so that it is convenient to use 6686d7f5d3SJohn Marino * lzma_stream_flags_compare() when both Stream Header and Stream 6786d7f5d3SJohn Marino * Footer have been decoded. 6886d7f5d3SJohn Marino */ 6986d7f5d3SJohn Marino lzma_vli backward_size; 7086d7f5d3SJohn Marino # define LZMA_BACKWARD_SIZE_MIN 4 7186d7f5d3SJohn Marino # define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34) 7286d7f5d3SJohn Marino 7386d7f5d3SJohn Marino /** 7486d7f5d3SJohn Marino * \brief Check ID 7586d7f5d3SJohn Marino * 7686d7f5d3SJohn Marino * This indicates the type of the integrity check calculated from 7786d7f5d3SJohn Marino * uncompressed data. 7886d7f5d3SJohn Marino */ 7986d7f5d3SJohn Marino lzma_check check; 8086d7f5d3SJohn Marino 8186d7f5d3SJohn Marino /* 8286d7f5d3SJohn Marino * Reserved space to allow possible future extensions without 8386d7f5d3SJohn Marino * breaking the ABI. You should not touch these, because the 8486d7f5d3SJohn Marino * names of these variables may change. 8586d7f5d3SJohn Marino * 8686d7f5d3SJohn Marino * (We will never be able to use all of these since Stream Flags 8786d7f5d3SJohn Marino * is just two bytes plus Backward Size of four bytes. But it's 8886d7f5d3SJohn Marino * nice to have the proper types when they are needed.) 8986d7f5d3SJohn Marino */ 9086d7f5d3SJohn Marino lzma_reserved_enum reserved_enum1; 9186d7f5d3SJohn Marino lzma_reserved_enum reserved_enum2; 9286d7f5d3SJohn Marino lzma_reserved_enum reserved_enum3; 9386d7f5d3SJohn Marino lzma_reserved_enum reserved_enum4; 9486d7f5d3SJohn Marino lzma_bool reserved_bool1; 9586d7f5d3SJohn Marino lzma_bool reserved_bool2; 9686d7f5d3SJohn Marino lzma_bool reserved_bool3; 9786d7f5d3SJohn Marino lzma_bool reserved_bool4; 9886d7f5d3SJohn Marino lzma_bool reserved_bool5; 9986d7f5d3SJohn Marino lzma_bool reserved_bool6; 10086d7f5d3SJohn Marino lzma_bool reserved_bool7; 10186d7f5d3SJohn Marino lzma_bool reserved_bool8; 10286d7f5d3SJohn Marino uint32_t reserved_int1; 10386d7f5d3SJohn Marino uint32_t reserved_int2; 10486d7f5d3SJohn Marino 10586d7f5d3SJohn Marino } lzma_stream_flags; 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marino 10886d7f5d3SJohn Marino /** 10986d7f5d3SJohn Marino * \brief Encode Stream Header 11086d7f5d3SJohn Marino * 11186d7f5d3SJohn Marino * \param options Stream Header options to be encoded. 11286d7f5d3SJohn Marino * options->backward_size is ignored and doesn't 11386d7f5d3SJohn Marino * need to be initialized. 11486d7f5d3SJohn Marino * \param out Beginning of the output buffer of 11586d7f5d3SJohn Marino * LZMA_STREAM_HEADER_SIZE bytes. 11686d7f5d3SJohn Marino * 11786d7f5d3SJohn Marino * \return - LZMA_OK: Encoding was successful. 11886d7f5d3SJohn Marino * - LZMA_OPTIONS_ERROR: options->version is not supported by 11986d7f5d3SJohn Marino * this liblzma version. 12086d7f5d3SJohn Marino * - LZMA_PROG_ERROR: Invalid options. 12186d7f5d3SJohn Marino */ 12286d7f5d3SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_header_encode( 12386d7f5d3SJohn Marino const lzma_stream_flags *options, uint8_t *out) 12486d7f5d3SJohn Marino lzma_nothrow lzma_attr_warn_unused_result; 12586d7f5d3SJohn Marino 12686d7f5d3SJohn Marino 12786d7f5d3SJohn Marino /** 12886d7f5d3SJohn Marino * \brief Encode Stream Footer 12986d7f5d3SJohn Marino * 13086d7f5d3SJohn Marino * \param options Stream Footer options to be encoded. 13186d7f5d3SJohn Marino * \param out Beginning of the output buffer of 13286d7f5d3SJohn Marino * LZMA_STREAM_HEADER_SIZE bytes. 13386d7f5d3SJohn Marino * 13486d7f5d3SJohn Marino * \return - LZMA_OK: Encoding was successful. 13586d7f5d3SJohn Marino * - LZMA_OPTIONS_ERROR: options->version is not supported by 13686d7f5d3SJohn Marino * this liblzma version. 13786d7f5d3SJohn Marino * - LZMA_PROG_ERROR: Invalid options. 13886d7f5d3SJohn Marino */ 13986d7f5d3SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_footer_encode( 14086d7f5d3SJohn Marino const lzma_stream_flags *options, uint8_t *out) 14186d7f5d3SJohn Marino lzma_nothrow lzma_attr_warn_unused_result; 14286d7f5d3SJohn Marino 14386d7f5d3SJohn Marino 14486d7f5d3SJohn Marino /** 14586d7f5d3SJohn Marino * \brief Decode Stream Header 14686d7f5d3SJohn Marino * 14786d7f5d3SJohn Marino * \param options Target for the decoded Stream Header options. 14886d7f5d3SJohn Marino * \param in Beginning of the input buffer of 14986d7f5d3SJohn Marino * LZMA_STREAM_HEADER_SIZE bytes. 15086d7f5d3SJohn Marino * 15186d7f5d3SJohn Marino * options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to 15286d7f5d3SJohn Marino * help comparing Stream Flags from Stream Header and Stream Footer with 15386d7f5d3SJohn Marino * lzma_stream_flags_compare(). 15486d7f5d3SJohn Marino * 15586d7f5d3SJohn Marino * \return - LZMA_OK: Decoding was successful. 15686d7f5d3SJohn Marino * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given 15786d7f5d3SJohn Marino * buffer cannot be Stream Header. 15886d7f5d3SJohn Marino * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header 15986d7f5d3SJohn Marino * is corrupt. 16086d7f5d3SJohn Marino * - LZMA_OPTIONS_ERROR: Unsupported options are present 16186d7f5d3SJohn Marino * in the header. 16286d7f5d3SJohn Marino * 16386d7f5d3SJohn Marino * \note When decoding .xz files that contain multiple Streams, it may 16486d7f5d3SJohn Marino * make sense to print "file format not recognized" only if 16586d7f5d3SJohn Marino * decoding of the Stream Header of the _first_ Stream gives 16686d7f5d3SJohn Marino * LZMA_FORMAT_ERROR. If non-first Stream Header gives 16786d7f5d3SJohn Marino * LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is 16886d7f5d3SJohn Marino * probably more appropriate. 16986d7f5d3SJohn Marino * 17086d7f5d3SJohn Marino * For example, Stream decoder in liblzma uses LZMA_DATA_ERROR if 17186d7f5d3SJohn Marino * LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode() 17286d7f5d3SJohn Marino * when decoding non-first Stream. 17386d7f5d3SJohn Marino */ 17486d7f5d3SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_header_decode( 17586d7f5d3SJohn Marino lzma_stream_flags *options, const uint8_t *in) 17686d7f5d3SJohn Marino lzma_nothrow lzma_attr_warn_unused_result; 17786d7f5d3SJohn Marino 17886d7f5d3SJohn Marino 17986d7f5d3SJohn Marino /** 18086d7f5d3SJohn Marino * \brief Decode Stream Footer 18186d7f5d3SJohn Marino * 18286d7f5d3SJohn Marino * \param options Target for the decoded Stream Header options. 18386d7f5d3SJohn Marino * \param in Beginning of the input buffer of 18486d7f5d3SJohn Marino * LZMA_STREAM_HEADER_SIZE bytes. 18586d7f5d3SJohn Marino * 18686d7f5d3SJohn Marino * \return - LZMA_OK: Decoding was successful. 18786d7f5d3SJohn Marino * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given 18886d7f5d3SJohn Marino * buffer cannot be Stream Footer. 18986d7f5d3SJohn Marino * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer 19086d7f5d3SJohn Marino * is corrupt. 19186d7f5d3SJohn Marino * - LZMA_OPTIONS_ERROR: Unsupported options are present 19286d7f5d3SJohn Marino * in Stream Footer. 19386d7f5d3SJohn Marino * 19486d7f5d3SJohn Marino * \note If Stream Header was already decoded successfully, but 19586d7f5d3SJohn Marino * decoding Stream Footer returns LZMA_FORMAT_ERROR, the 19686d7f5d3SJohn Marino * application should probably report some other error message 19786d7f5d3SJohn Marino * than "file format not recognized", since the file more likely 19886d7f5d3SJohn Marino * is corrupt (possibly truncated). Stream decoder in liblzma 19986d7f5d3SJohn Marino * uses LZMA_DATA_ERROR in this situation. 20086d7f5d3SJohn Marino */ 20186d7f5d3SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_footer_decode( 20286d7f5d3SJohn Marino lzma_stream_flags *options, const uint8_t *in) 20386d7f5d3SJohn Marino lzma_nothrow lzma_attr_warn_unused_result; 20486d7f5d3SJohn Marino 20586d7f5d3SJohn Marino 20686d7f5d3SJohn Marino /** 20786d7f5d3SJohn Marino * \brief Compare two lzma_stream_flags structures 20886d7f5d3SJohn Marino * 20986d7f5d3SJohn Marino * backward_size values are compared only if both are not 21086d7f5d3SJohn Marino * LZMA_VLI_UNKNOWN. 21186d7f5d3SJohn Marino * 21286d7f5d3SJohn Marino * \return - LZMA_OK: Both are equal. If either had backward_size set 21386d7f5d3SJohn Marino * to LZMA_VLI_UNKNOWN, backward_size values were not 21486d7f5d3SJohn Marino * compared or validated. 21586d7f5d3SJohn Marino * - LZMA_DATA_ERROR: The structures differ. 21686d7f5d3SJohn Marino * - LZMA_OPTIONS_ERROR: version in either structure is greater 21786d7f5d3SJohn Marino * than the maximum supported version (currently zero). 21886d7f5d3SJohn Marino * - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or 21986d7f5d3SJohn Marino * backward_size. 22086d7f5d3SJohn Marino */ 22186d7f5d3SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_flags_compare( 22286d7f5d3SJohn Marino const lzma_stream_flags *a, const lzma_stream_flags *b) 22386d7f5d3SJohn Marino lzma_nothrow lzma_attr_pure; 224