1*3b35e7eeSXin LI /* SPDX-License-Identifier: 0BSD */ 2*3b35e7eeSXin LI 381ad8388SMartin Matuska /** 481ad8388SMartin Matuska * \file lzma/index.h 581ad8388SMartin Matuska * \brief Handling of .xz Index and related information 6c917796cSXin LI * \note Never include this file directly. Use <lzma.h> instead. 781ad8388SMartin Matuska */ 881ad8388SMartin Matuska 981ad8388SMartin Matuska /* 1081ad8388SMartin Matuska * Author: Lasse Collin 1181ad8388SMartin Matuska */ 1281ad8388SMartin Matuska 1381ad8388SMartin Matuska #ifndef LZMA_H_INTERNAL 1481ad8388SMartin Matuska # error Never include this file directly. Use <lzma.h> instead. 1581ad8388SMartin Matuska #endif 1681ad8388SMartin Matuska 1781ad8388SMartin Matuska 1881ad8388SMartin Matuska /** 1981ad8388SMartin Matuska * \brief Opaque data type to hold the Index(es) and other information 2081ad8388SMartin Matuska * 2181ad8388SMartin Matuska * lzma_index often holds just one .xz Index and possibly the Stream Flags 2281ad8388SMartin Matuska * of the same Stream and size of the Stream Padding field. However, 2381ad8388SMartin Matuska * multiple lzma_indexes can be concatenated with lzma_index_cat() and then 2481ad8388SMartin Matuska * there may be information about multiple Streams in the same lzma_index. 2581ad8388SMartin Matuska * 2681ad8388SMartin Matuska * Notes about thread safety: Only one thread may modify lzma_index at 2781ad8388SMartin Matuska * a time. All functions that take non-const pointer to lzma_index 2881ad8388SMartin Matuska * modify it. As long as no thread is modifying the lzma_index, getting 2981ad8388SMartin Matuska * information from the same lzma_index can be done from multiple threads 3081ad8388SMartin Matuska * at the same time with functions that take a const pointer to 3181ad8388SMartin Matuska * lzma_index or use lzma_index_iter. The same iterator must be used 3281ad8388SMartin Matuska * only by one thread at a time, of course, but there can be as many 3381ad8388SMartin Matuska * iterators for the same lzma_index as needed. 3481ad8388SMartin Matuska */ 3581ad8388SMartin Matuska typedef struct lzma_index_s lzma_index; 3681ad8388SMartin Matuska 3781ad8388SMartin Matuska 3881ad8388SMartin Matuska /** 3981ad8388SMartin Matuska * \brief Iterator to get information about Blocks and Streams 4081ad8388SMartin Matuska */ 4181ad8388SMartin Matuska typedef struct { 4281ad8388SMartin Matuska struct { 4381ad8388SMartin Matuska /** 4481ad8388SMartin Matuska * \brief Pointer to Stream Flags 4581ad8388SMartin Matuska * 4681ad8388SMartin Matuska * This is NULL if Stream Flags have not been set for 4781ad8388SMartin Matuska * this Stream with lzma_index_stream_flags(). 4881ad8388SMartin Matuska */ 4981ad8388SMartin Matuska const lzma_stream_flags *flags; 5081ad8388SMartin Matuska 51c917796cSXin LI /** \private Reserved member. */ 5281ad8388SMartin Matuska const void *reserved_ptr1; 53c917796cSXin LI 54c917796cSXin LI /** \private Reserved member. */ 5581ad8388SMartin Matuska const void *reserved_ptr2; 56c917796cSXin LI 57c917796cSXin LI /** \private Reserved member. */ 5881ad8388SMartin Matuska const void *reserved_ptr3; 5981ad8388SMartin Matuska 6081ad8388SMartin Matuska /** 6181ad8388SMartin Matuska * \brief Stream number in the lzma_index 6281ad8388SMartin Matuska * 6381ad8388SMartin Matuska * The first Stream is 1. 6481ad8388SMartin Matuska */ 6581ad8388SMartin Matuska lzma_vli number; 6681ad8388SMartin Matuska 6781ad8388SMartin Matuska /** 6881ad8388SMartin Matuska * \brief Number of Blocks in the Stream 6981ad8388SMartin Matuska * 7081ad8388SMartin Matuska * If this is zero, the block structure below has 7181ad8388SMartin Matuska * undefined values. 7281ad8388SMartin Matuska */ 7381ad8388SMartin Matuska lzma_vli block_count; 7481ad8388SMartin Matuska 7581ad8388SMartin Matuska /** 7681ad8388SMartin Matuska * \brief Compressed start offset of this Stream 7781ad8388SMartin Matuska * 7881ad8388SMartin Matuska * The offset is relative to the beginning of the lzma_index 7981ad8388SMartin Matuska * (i.e. usually the beginning of the .xz file). 8081ad8388SMartin Matuska */ 8181ad8388SMartin Matuska lzma_vli compressed_offset; 8281ad8388SMartin Matuska 8381ad8388SMartin Matuska /** 8481ad8388SMartin Matuska * \brief Uncompressed start offset of this Stream 8581ad8388SMartin Matuska * 8681ad8388SMartin Matuska * The offset is relative to the beginning of the lzma_index 8781ad8388SMartin Matuska * (i.e. usually the beginning of the .xz file). 8881ad8388SMartin Matuska */ 8981ad8388SMartin Matuska lzma_vli uncompressed_offset; 9081ad8388SMartin Matuska 9181ad8388SMartin Matuska /** 9281ad8388SMartin Matuska * \brief Compressed size of this Stream 9381ad8388SMartin Matuska * 9481ad8388SMartin Matuska * This includes all headers except the possible 9581ad8388SMartin Matuska * Stream Padding after this Stream. 9681ad8388SMartin Matuska */ 9781ad8388SMartin Matuska lzma_vli compressed_size; 9881ad8388SMartin Matuska 9981ad8388SMartin Matuska /** 10081ad8388SMartin Matuska * \brief Uncompressed size of this Stream 10181ad8388SMartin Matuska */ 10281ad8388SMartin Matuska lzma_vli uncompressed_size; 10381ad8388SMartin Matuska 10481ad8388SMartin Matuska /** 10581ad8388SMartin Matuska * \brief Size of Stream Padding after this Stream 10681ad8388SMartin Matuska * 10781ad8388SMartin Matuska * If it hasn't been set with lzma_index_stream_padding(), 10881ad8388SMartin Matuska * this defaults to zero. Stream Padding is always 10981ad8388SMartin Matuska * a multiple of four bytes. 11081ad8388SMartin Matuska */ 11181ad8388SMartin Matuska lzma_vli padding; 11281ad8388SMartin Matuska 113c917796cSXin LI 114c917796cSXin LI /** \private Reserved member. */ 11581ad8388SMartin Matuska lzma_vli reserved_vli1; 116c917796cSXin LI 117c917796cSXin LI /** \private Reserved member. */ 11881ad8388SMartin Matuska lzma_vli reserved_vli2; 119c917796cSXin LI 120c917796cSXin LI /** \private Reserved member. */ 12181ad8388SMartin Matuska lzma_vli reserved_vli3; 122c917796cSXin LI 123c917796cSXin LI /** \private Reserved member. */ 12481ad8388SMartin Matuska lzma_vli reserved_vli4; 12581ad8388SMartin Matuska } stream; 12681ad8388SMartin Matuska 12781ad8388SMartin Matuska struct { 12881ad8388SMartin Matuska /** 12981ad8388SMartin Matuska * \brief Block number in the file 13081ad8388SMartin Matuska * 13181ad8388SMartin Matuska * The first Block is 1. 13281ad8388SMartin Matuska */ 13381ad8388SMartin Matuska lzma_vli number_in_file; 13481ad8388SMartin Matuska 13581ad8388SMartin Matuska /** 13681ad8388SMartin Matuska * \brief Compressed start offset of this Block 13781ad8388SMartin Matuska * 13881ad8388SMartin Matuska * This offset is relative to the beginning of the 13981ad8388SMartin Matuska * lzma_index (i.e. usually the beginning of the .xz file). 14081ad8388SMartin Matuska * Normally this is where you should seek in the .xz file 14181ad8388SMartin Matuska * to start decompressing this Block. 14281ad8388SMartin Matuska */ 14381ad8388SMartin Matuska lzma_vli compressed_file_offset; 14481ad8388SMartin Matuska 14581ad8388SMartin Matuska /** 14681ad8388SMartin Matuska * \brief Uncompressed start offset of this Block 14781ad8388SMartin Matuska * 14881ad8388SMartin Matuska * This offset is relative to the beginning of the lzma_index 14981ad8388SMartin Matuska * (i.e. usually the beginning of the .xz file). 150542aef48SMartin Matuska * 151542aef48SMartin Matuska * When doing random-access reading, it is possible that 152542aef48SMartin Matuska * the target offset is not exactly at Block boundary. One 153542aef48SMartin Matuska * will need to compare the target offset against 154542aef48SMartin Matuska * uncompressed_file_offset or uncompressed_stream_offset, 155542aef48SMartin Matuska * and possibly decode and throw away some amount of data 156542aef48SMartin Matuska * before reaching the target offset. 15781ad8388SMartin Matuska */ 15881ad8388SMartin Matuska lzma_vli uncompressed_file_offset; 15981ad8388SMartin Matuska 16081ad8388SMartin Matuska /** 16181ad8388SMartin Matuska * \brief Block number in this Stream 16281ad8388SMartin Matuska * 16381ad8388SMartin Matuska * The first Block is 1. 16481ad8388SMartin Matuska */ 16581ad8388SMartin Matuska lzma_vli number_in_stream; 16681ad8388SMartin Matuska 16781ad8388SMartin Matuska /** 16881ad8388SMartin Matuska * \brief Compressed start offset of this Block 16981ad8388SMartin Matuska * 17081ad8388SMartin Matuska * This offset is relative to the beginning of the Stream 17181ad8388SMartin Matuska * containing this Block. 17281ad8388SMartin Matuska */ 17381ad8388SMartin Matuska lzma_vli compressed_stream_offset; 17481ad8388SMartin Matuska 17581ad8388SMartin Matuska /** 17681ad8388SMartin Matuska * \brief Uncompressed start offset of this Block 17781ad8388SMartin Matuska * 17881ad8388SMartin Matuska * This offset is relative to the beginning of the Stream 17981ad8388SMartin Matuska * containing this Block. 18081ad8388SMartin Matuska */ 18181ad8388SMartin Matuska lzma_vli uncompressed_stream_offset; 18281ad8388SMartin Matuska 18381ad8388SMartin Matuska /** 18481ad8388SMartin Matuska * \brief Uncompressed size of this Block 18581ad8388SMartin Matuska * 18681ad8388SMartin Matuska * You should pass this to the Block decoder if you will 187542aef48SMartin Matuska * decode this Block. It will allow the Block decoder to 188542aef48SMartin Matuska * validate the uncompressed size. 18981ad8388SMartin Matuska */ 19081ad8388SMartin Matuska lzma_vli uncompressed_size; 19181ad8388SMartin Matuska 19281ad8388SMartin Matuska /** 19381ad8388SMartin Matuska * \brief Unpadded size of this Block 19481ad8388SMartin Matuska * 19581ad8388SMartin Matuska * You should pass this to the Block decoder if you will 196542aef48SMartin Matuska * decode this Block. It will allow the Block decoder to 197542aef48SMartin Matuska * validate the unpadded size. 19881ad8388SMartin Matuska */ 19981ad8388SMartin Matuska lzma_vli unpadded_size; 20081ad8388SMartin Matuska 20181ad8388SMartin Matuska /** 20281ad8388SMartin Matuska * \brief Total compressed size 20381ad8388SMartin Matuska * 20481ad8388SMartin Matuska * This includes all headers and padding in this Block. 20581ad8388SMartin Matuska * This is useful if you need to know how many bytes 20681ad8388SMartin Matuska * the Block decoder will actually read. 20781ad8388SMartin Matuska */ 20881ad8388SMartin Matuska lzma_vli total_size; 20981ad8388SMartin Matuska 210c917796cSXin LI /** \private Reserved member. */ 21181ad8388SMartin Matuska lzma_vli reserved_vli1; 212c917796cSXin LI 213c917796cSXin LI /** \private Reserved member. */ 21481ad8388SMartin Matuska lzma_vli reserved_vli2; 215c917796cSXin LI 216c917796cSXin LI /** \private Reserved member. */ 21781ad8388SMartin Matuska lzma_vli reserved_vli3; 218c917796cSXin LI 219c917796cSXin LI /** \private Reserved member. */ 22081ad8388SMartin Matuska lzma_vli reserved_vli4; 22181ad8388SMartin Matuska 222c917796cSXin LI /** \private Reserved member. */ 22381ad8388SMartin Matuska const void *reserved_ptr1; 224c917796cSXin LI 225c917796cSXin LI /** \private Reserved member. */ 22681ad8388SMartin Matuska const void *reserved_ptr2; 227c917796cSXin LI 228c917796cSXin LI /** \private Reserved member. */ 22981ad8388SMartin Matuska const void *reserved_ptr3; 230c917796cSXin LI 231c917796cSXin LI /** \private Reserved member. */ 23281ad8388SMartin Matuska const void *reserved_ptr4; 23381ad8388SMartin Matuska } block; 23481ad8388SMartin Matuska 235c917796cSXin LI /** 236*3b35e7eeSXin LI * \private Internal data 237c917796cSXin LI * 23881ad8388SMartin Matuska * Internal data which is used to store the state of the iterator. 23981ad8388SMartin Matuska * The exact format may vary between liblzma versions, so don't 24081ad8388SMartin Matuska * touch these in any way. 24181ad8388SMartin Matuska */ 24281ad8388SMartin Matuska union { 243c917796cSXin LI /** \private Internal member. */ 24481ad8388SMartin Matuska const void *p; 245c917796cSXin LI 246c917796cSXin LI /** \private Internal member. */ 24781ad8388SMartin Matuska size_t s; 248c917796cSXin LI 249c917796cSXin LI /** \private Internal member. */ 25081ad8388SMartin Matuska lzma_vli v; 25181ad8388SMartin Matuska } internal[6]; 25281ad8388SMartin Matuska } lzma_index_iter; 25381ad8388SMartin Matuska 25481ad8388SMartin Matuska 25581ad8388SMartin Matuska /** 25681ad8388SMartin Matuska * \brief Operation mode for lzma_index_iter_next() 25781ad8388SMartin Matuska */ 25881ad8388SMartin Matuska typedef enum { 25981ad8388SMartin Matuska LZMA_INDEX_ITER_ANY = 0, 26081ad8388SMartin Matuska /**< 26181ad8388SMartin Matuska * \brief Get the next Block or Stream 26281ad8388SMartin Matuska * 26381ad8388SMartin Matuska * Go to the next Block if the current Stream has at least 26481ad8388SMartin Matuska * one Block left. Otherwise go to the next Stream even if 26581ad8388SMartin Matuska * it has no Blocks. If the Stream has no Blocks 26681ad8388SMartin Matuska * (lzma_index_iter.stream.block_count == 0), 26781ad8388SMartin Matuska * lzma_index_iter.block will have undefined values. 26881ad8388SMartin Matuska */ 26981ad8388SMartin Matuska 27081ad8388SMartin Matuska LZMA_INDEX_ITER_STREAM = 1, 27181ad8388SMartin Matuska /**< 27281ad8388SMartin Matuska * \brief Get the next Stream 27381ad8388SMartin Matuska * 27481ad8388SMartin Matuska * Go to the next Stream even if the current Stream has 27581ad8388SMartin Matuska * unread Blocks left. If the next Stream has at least one 27681ad8388SMartin Matuska * Block, the iterator will point to the first Block. 27781ad8388SMartin Matuska * If there are no Blocks, lzma_index_iter.block will have 27881ad8388SMartin Matuska * undefined values. 27981ad8388SMartin Matuska */ 28081ad8388SMartin Matuska 28181ad8388SMartin Matuska LZMA_INDEX_ITER_BLOCK = 2, 28281ad8388SMartin Matuska /**< 28381ad8388SMartin Matuska * \brief Get the next Block 28481ad8388SMartin Matuska * 28581ad8388SMartin Matuska * Go to the next Block if the current Stream has at least 28681ad8388SMartin Matuska * one Block left. If the current Stream has no Blocks left, 28781ad8388SMartin Matuska * the next Stream with at least one Block is located and 28881ad8388SMartin Matuska * the iterator will be made to point to the first Block of 28981ad8388SMartin Matuska * that Stream. 29081ad8388SMartin Matuska */ 29181ad8388SMartin Matuska 29281ad8388SMartin Matuska LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3 29381ad8388SMartin Matuska /**< 29481ad8388SMartin Matuska * \brief Get the next non-empty Block 29581ad8388SMartin Matuska * 29681ad8388SMartin Matuska * This is like LZMA_INDEX_ITER_BLOCK except that it will 29781ad8388SMartin Matuska * skip Blocks whose Uncompressed Size is zero. 29881ad8388SMartin Matuska */ 29981ad8388SMartin Matuska 30081ad8388SMartin Matuska } lzma_index_iter_mode; 30181ad8388SMartin Matuska 30281ad8388SMartin Matuska 30381ad8388SMartin Matuska /** 304*3b35e7eeSXin LI * \brief Mask for return value from lzma_index_checks() for check none 305*3b35e7eeSXin LI * 306*3b35e7eeSXin LI * \note This and the other CHECK_MASK macros were added in 5.5.1alpha. 307*3b35e7eeSXin LI */ 308*3b35e7eeSXin LI #define LZMA_INDEX_CHECK_MASK_NONE (UINT32_C(1) << LZMA_CHECK_NONE) 309*3b35e7eeSXin LI 310*3b35e7eeSXin LI /** 311*3b35e7eeSXin LI * \brief Mask for return value from lzma_index_checks() for check CRC32 312*3b35e7eeSXin LI */ 313*3b35e7eeSXin LI #define LZMA_INDEX_CHECK_MASK_CRC32 (UINT32_C(1) << LZMA_CHECK_CRC32) 314*3b35e7eeSXin LI 315*3b35e7eeSXin LI /** 316*3b35e7eeSXin LI * \brief Mask for return value from lzma_index_checks() for check CRC64 317*3b35e7eeSXin LI */ 318*3b35e7eeSXin LI #define LZMA_INDEX_CHECK_MASK_CRC64 (UINT32_C(1) << LZMA_CHECK_CRC64) 319*3b35e7eeSXin LI 320*3b35e7eeSXin LI /** 321*3b35e7eeSXin LI * \brief Mask for return value from lzma_index_checks() for check SHA256 322*3b35e7eeSXin LI */ 323*3b35e7eeSXin LI #define LZMA_INDEX_CHECK_MASK_SHA256 (UINT32_C(1) << LZMA_CHECK_SHA256) 324*3b35e7eeSXin LI 325*3b35e7eeSXin LI /** 32681ad8388SMartin Matuska * \brief Calculate memory usage of lzma_index 32781ad8388SMartin Matuska * 32881ad8388SMartin Matuska * On disk, the size of the Index field depends on both the number of Records 329c917796cSXin LI * stored and the size of the Records (due to variable-length integer 33081ad8388SMartin Matuska * encoding). When the Index is kept in lzma_index structure, the memory usage 33181ad8388SMartin Matuska * depends only on the number of Records/Blocks stored in the Index(es), and 33281ad8388SMartin Matuska * in case of concatenated lzma_indexes, the number of Streams. The size in 33381ad8388SMartin Matuska * RAM is almost always significantly bigger than in the encoded form on disk. 33481ad8388SMartin Matuska * 335c917796cSXin LI * This function calculates an approximate amount of memory needed to hold 33681ad8388SMartin Matuska * the given number of Streams and Blocks in lzma_index structure. This 33781ad8388SMartin Matuska * value may vary between CPU architectures and also between liblzma versions 33881ad8388SMartin Matuska * if the internal implementation is modified. 339c917796cSXin LI * 340c917796cSXin LI * \param streams Number of Streams 341c917796cSXin LI * \param blocks Number of Blocks 342c917796cSXin LI * 343c917796cSXin LI * \return Approximate memory in bytes needed in a lzma_index structure. 34481ad8388SMartin Matuska */ 34581ad8388SMartin Matuska extern LZMA_API(uint64_t) lzma_index_memusage( 34681ad8388SMartin Matuska lzma_vli streams, lzma_vli blocks) lzma_nothrow; 34781ad8388SMartin Matuska 34881ad8388SMartin Matuska 34981ad8388SMartin Matuska /** 35081ad8388SMartin Matuska * \brief Calculate the memory usage of an existing lzma_index 35181ad8388SMartin Matuska * 35281ad8388SMartin Matuska * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), 35381ad8388SMartin Matuska * lzma_index_block_count(i)). 354c917796cSXin LI * 355c917796cSXin LI * \param i Pointer to lzma_index structure 356c917796cSXin LI * 357c917796cSXin LI * \return Approximate memory in bytes used by the lzma_index structure. 35881ad8388SMartin Matuska */ 35981ad8388SMartin Matuska extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) 36081ad8388SMartin Matuska lzma_nothrow; 36181ad8388SMartin Matuska 36281ad8388SMartin Matuska 36381ad8388SMartin Matuska /** 36481ad8388SMartin Matuska * \brief Allocate and initialize a new lzma_index structure 36581ad8388SMartin Matuska * 366c917796cSXin LI * \param allocator lzma_allocator for custom allocator functions. 367c917796cSXin LI * Set to NULL to use malloc() and free(). 368c917796cSXin LI * 36981ad8388SMartin Matuska * \return On success, a pointer to an empty initialized lzma_index is 37081ad8388SMartin Matuska * returned. If allocation fails, NULL is returned. 37181ad8388SMartin Matuska */ 37253200025SRui Paulo extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator) 37381ad8388SMartin Matuska lzma_nothrow; 37481ad8388SMartin Matuska 37581ad8388SMartin Matuska 37681ad8388SMartin Matuska /** 37781ad8388SMartin Matuska * \brief Deallocate lzma_index 37881ad8388SMartin Matuska * 37981ad8388SMartin Matuska * If i is NULL, this does nothing. 380c917796cSXin LI * 381c917796cSXin LI * \param i Pointer to lzma_index structure to deallocate 382c917796cSXin LI * \param allocator lzma_allocator for custom allocator functions. 383c917796cSXin LI * Set to NULL to use malloc() and free(). 38481ad8388SMartin Matuska */ 38553200025SRui Paulo extern LZMA_API(void) lzma_index_end( 38653200025SRui Paulo lzma_index *i, const lzma_allocator *allocator) lzma_nothrow; 38781ad8388SMartin Matuska 38881ad8388SMartin Matuska 38981ad8388SMartin Matuska /** 39081ad8388SMartin Matuska * \brief Add a new Block to lzma_index 39181ad8388SMartin Matuska * 39281ad8388SMartin Matuska * \param i Pointer to a lzma_index structure 393c917796cSXin LI * \param allocator lzma_allocator for custom allocator 394c917796cSXin LI * functions. Set to NULL to use malloc() 395c917796cSXin LI * and free(). 39681ad8388SMartin Matuska * \param unpadded_size Unpadded Size of a Block. This can be 39781ad8388SMartin Matuska * calculated with lzma_block_unpadded_size() 39881ad8388SMartin Matuska * after encoding or decoding the Block. 39981ad8388SMartin Matuska * \param uncompressed_size Uncompressed Size of a Block. This can be 40081ad8388SMartin Matuska * taken directly from lzma_block structure 40181ad8388SMartin Matuska * after encoding or decoding the Block. 40281ad8388SMartin Matuska * 40381ad8388SMartin Matuska * Appending a new Block does not invalidate iterators. For example, 40481ad8388SMartin Matuska * if an iterator was pointing to the end of the lzma_index, after 40581ad8388SMartin Matuska * lzma_index_append() it is possible to read the next Block with 40681ad8388SMartin Matuska * an existing iterator. 40781ad8388SMartin Matuska * 408c917796cSXin LI * \return Possible lzma_ret values: 409c917796cSXin LI * - LZMA_OK 41081ad8388SMartin Matuska * - LZMA_MEM_ERROR 41181ad8388SMartin Matuska * - LZMA_DATA_ERROR: Compressed or uncompressed size of the 41281ad8388SMartin Matuska * Stream or size of the Index field would grow too big. 41381ad8388SMartin Matuska * - LZMA_PROG_ERROR 41481ad8388SMartin Matuska */ 41581ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_append( 41653200025SRui Paulo lzma_index *i, const lzma_allocator *allocator, 41781ad8388SMartin Matuska lzma_vli unpadded_size, lzma_vli uncompressed_size) 41881ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 41981ad8388SMartin Matuska 42081ad8388SMartin Matuska 42181ad8388SMartin Matuska /** 42281ad8388SMartin Matuska * \brief Set the Stream Flags 42381ad8388SMartin Matuska * 42481ad8388SMartin Matuska * Set the Stream Flags of the last (and typically the only) Stream 42581ad8388SMartin Matuska * in lzma_index. This can be useful when reading information from the 42681ad8388SMartin Matuska * lzma_index, because to decode Blocks, knowing the integrity check type 42781ad8388SMartin Matuska * is needed. 42881ad8388SMartin Matuska * 429c917796cSXin LI * \param i Pointer to lzma_index structure 430c917796cSXin LI * \param stream_flags Pointer to lzma_stream_flags structure. This 431c917796cSXin LI * is copied into the internal preallocated 432c917796cSXin LI * structure, so the caller doesn't need to keep 433c917796cSXin LI * the flags' data available after calling this 434c917796cSXin LI * function. 43581ad8388SMartin Matuska * 436c917796cSXin LI * \return Possible lzma_ret values: 437c917796cSXin LI * - LZMA_OK 43881ad8388SMartin Matuska * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version. 43981ad8388SMartin Matuska * - LZMA_PROG_ERROR 44081ad8388SMartin Matuska */ 44181ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_stream_flags( 44281ad8388SMartin Matuska lzma_index *i, const lzma_stream_flags *stream_flags) 44381ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 44481ad8388SMartin Matuska 44581ad8388SMartin Matuska 44681ad8388SMartin Matuska /** 44781ad8388SMartin Matuska * \brief Get the types of integrity Checks 44881ad8388SMartin Matuska * 449e0f0e66dSMartin Matuska * If lzma_index_stream_flags() is used to set the Stream Flags for 45081ad8388SMartin Matuska * every Stream, lzma_index_checks() can be used to get a bitmask to 45181ad8388SMartin Matuska * indicate which Check types have been used. It can be useful e.g. if 45281ad8388SMartin Matuska * showing the Check types to the user. 45381ad8388SMartin Matuska * 45481ad8388SMartin Matuska * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10. 455*3b35e7eeSXin LI * These masks are defined for convenience as LZMA_INDEX_CHECK_MASK_XXX 456c917796cSXin LI * 457c917796cSXin LI * \param i Pointer to lzma_index structure 458c917796cSXin LI * 459c917796cSXin LI * \return Bitmask indicating which Check types are used in the lzma_index 46081ad8388SMartin Matuska */ 46181ad8388SMartin Matuska extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i) 46281ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 46381ad8388SMartin Matuska 46481ad8388SMartin Matuska 46581ad8388SMartin Matuska /** 46681ad8388SMartin Matuska * \brief Set the amount of Stream Padding 46781ad8388SMartin Matuska * 46881ad8388SMartin Matuska * Set the amount of Stream Padding of the last (and typically the only) 46981ad8388SMartin Matuska * Stream in the lzma_index. This is needed when planning to do random-access 47081ad8388SMartin Matuska * reading within multiple concatenated Streams. 47181ad8388SMartin Matuska * 47281ad8388SMartin Matuska * By default, the amount of Stream Padding is assumed to be zero bytes. 47381ad8388SMartin Matuska * 474c917796cSXin LI * \return Possible lzma_ret values: 475c917796cSXin LI * - LZMA_OK 47681ad8388SMartin Matuska * - LZMA_DATA_ERROR: The file size would grow too big. 47781ad8388SMartin Matuska * - LZMA_PROG_ERROR 47881ad8388SMartin Matuska */ 47981ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_stream_padding( 48081ad8388SMartin Matuska lzma_index *i, lzma_vli stream_padding) 48181ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 48281ad8388SMartin Matuska 48381ad8388SMartin Matuska 48481ad8388SMartin Matuska /** 48581ad8388SMartin Matuska * \brief Get the number of Streams 486c917796cSXin LI * 487c917796cSXin LI * \param i Pointer to lzma_index structure 488c917796cSXin LI * 489c917796cSXin LI * \return Number of Streams in the lzma_index 49081ad8388SMartin Matuska */ 49181ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i) 49281ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 49381ad8388SMartin Matuska 49481ad8388SMartin Matuska 49581ad8388SMartin Matuska /** 49681ad8388SMartin Matuska * \brief Get the number of Blocks 49781ad8388SMartin Matuska * 49881ad8388SMartin Matuska * This returns the total number of Blocks in lzma_index. To get number 49981ad8388SMartin Matuska * of Blocks in individual Streams, use lzma_index_iter. 500c917796cSXin LI * 501c917796cSXin LI * \param i Pointer to lzma_index structure 502c917796cSXin LI * 503c917796cSXin LI * \return Number of blocks in the lzma_index 50481ad8388SMartin Matuska */ 50581ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i) 50681ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 50781ad8388SMartin Matuska 50881ad8388SMartin Matuska 50981ad8388SMartin Matuska /** 51081ad8388SMartin Matuska * \brief Get the size of the Index field as bytes 51181ad8388SMartin Matuska * 51281ad8388SMartin Matuska * This is needed to verify the Backward Size field in the Stream Footer. 513c917796cSXin LI * 514c917796cSXin LI * \param i Pointer to lzma_index structure 515c917796cSXin LI * 516c917796cSXin LI * \return Size in bytes of the Index 51781ad8388SMartin Matuska */ 51881ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i) 51981ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 52081ad8388SMartin Matuska 52181ad8388SMartin Matuska 52281ad8388SMartin Matuska /** 52381ad8388SMartin Matuska * \brief Get the total size of the Stream 52481ad8388SMartin Matuska * 52581ad8388SMartin Matuska * If multiple lzma_indexes have been combined, this works as if the Blocks 52681ad8388SMartin Matuska * were in a single Stream. This is useful if you are going to combine 52781ad8388SMartin Matuska * Blocks from multiple Streams into a single new Stream. 528c917796cSXin LI * 529c917796cSXin LI * \param i Pointer to lzma_index structure 530c917796cSXin LI * 531c917796cSXin LI * \return Size in bytes of the Stream (if all Blocks are combined 532c917796cSXin LI * into one Stream). 53381ad8388SMartin Matuska */ 53481ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i) 53581ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 53681ad8388SMartin Matuska 53781ad8388SMartin Matuska 53881ad8388SMartin Matuska /** 53981ad8388SMartin Matuska * \brief Get the total size of the Blocks 54081ad8388SMartin Matuska * 54181ad8388SMartin Matuska * This doesn't include the Stream Header, Stream Footer, Stream Padding, 54281ad8388SMartin Matuska * or Index fields. 543c917796cSXin LI * 544c917796cSXin LI * \param i Pointer to lzma_index structure 545c917796cSXin LI * 546c917796cSXin LI * \return Size in bytes of all Blocks in the Stream(s) 54781ad8388SMartin Matuska */ 54881ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i) 54981ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 55081ad8388SMartin Matuska 55181ad8388SMartin Matuska 55281ad8388SMartin Matuska /** 55381ad8388SMartin Matuska * \brief Get the total size of the file 55481ad8388SMartin Matuska * 55581ad8388SMartin Matuska * When no lzma_indexes have been combined with lzma_index_cat() and there is 55681ad8388SMartin Matuska * no Stream Padding, this function is identical to lzma_index_stream_size(). 55781ad8388SMartin Matuska * If multiple lzma_indexes have been combined, this includes also the headers 55881ad8388SMartin Matuska * of each separate Stream and the possible Stream Padding fields. 559c917796cSXin LI * 560c917796cSXin LI * \param i Pointer to lzma_index structure 561c917796cSXin LI * 562c917796cSXin LI * \return Total size of the .xz file in bytes 56381ad8388SMartin Matuska */ 56481ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i) 56581ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 56681ad8388SMartin Matuska 56781ad8388SMartin Matuska 56881ad8388SMartin Matuska /** 56981ad8388SMartin Matuska * \brief Get the uncompressed size of the file 570c917796cSXin LI * 571c917796cSXin LI * \param i Pointer to lzma_index structure 572c917796cSXin LI * 573c917796cSXin LI * \return Size in bytes of the uncompressed data in the file 57481ad8388SMartin Matuska */ 57581ad8388SMartin Matuska extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i) 57681ad8388SMartin Matuska lzma_nothrow lzma_attr_pure; 57781ad8388SMartin Matuska 57881ad8388SMartin Matuska 57981ad8388SMartin Matuska /** 58081ad8388SMartin Matuska * \brief Initialize an iterator 58181ad8388SMartin Matuska * 58281ad8388SMartin Matuska * This function associates the iterator with the given lzma_index, and calls 58381ad8388SMartin Matuska * lzma_index_iter_rewind() on the iterator. 58481ad8388SMartin Matuska * 58581ad8388SMartin Matuska * This function doesn't allocate any memory, thus there is no 58681ad8388SMartin Matuska * lzma_index_iter_end(). The iterator is valid as long as the 58781ad8388SMartin Matuska * associated lzma_index is valid, that is, until lzma_index_end() or 58881ad8388SMartin Matuska * using it as source in lzma_index_cat(). Specifically, lzma_index doesn't 58981ad8388SMartin Matuska * become invalid if new Blocks are added to it with lzma_index_append() or 59081ad8388SMartin Matuska * if it is used as the destination in lzma_index_cat(). 59181ad8388SMartin Matuska * 59281ad8388SMartin Matuska * It is safe to make copies of an initialized lzma_index_iter, for example, 59381ad8388SMartin Matuska * to easily restart reading at some particular position. 594c917796cSXin LI * 595c917796cSXin LI * \param iter Pointer to a lzma_index_iter structure 596c917796cSXin LI * \param i lzma_index to which the iterator will be associated 59781ad8388SMartin Matuska */ 59881ad8388SMartin Matuska extern LZMA_API(void) lzma_index_iter_init( 59981ad8388SMartin Matuska lzma_index_iter *iter, const lzma_index *i) lzma_nothrow; 60081ad8388SMartin Matuska 60181ad8388SMartin Matuska 60281ad8388SMartin Matuska /** 60381ad8388SMartin Matuska * \brief Rewind the iterator 60481ad8388SMartin Matuska * 60581ad8388SMartin Matuska * Rewind the iterator so that next call to lzma_index_iter_next() will 60681ad8388SMartin Matuska * return the first Block or Stream. 607c917796cSXin LI * 608c917796cSXin LI * \param iter Pointer to a lzma_index_iter structure 60981ad8388SMartin Matuska */ 61081ad8388SMartin Matuska extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter) 61181ad8388SMartin Matuska lzma_nothrow; 61281ad8388SMartin Matuska 61381ad8388SMartin Matuska 61481ad8388SMartin Matuska /** 61581ad8388SMartin Matuska * \brief Get the next Block or Stream 61681ad8388SMartin Matuska * 61781ad8388SMartin Matuska * \param iter Iterator initialized with lzma_index_iter_init() 61881ad8388SMartin Matuska * \param mode Specify what kind of information the caller wants 61981ad8388SMartin Matuska * to get. See lzma_index_iter_mode for details. 62081ad8388SMartin Matuska * 621c917796cSXin LI * \return lzma_bool: 622c917796cSXin LI * - true if no Block or Stream matching the mode is found. 623c917796cSXin LI * *iter is not updated (failure). 624c917796cSXin LI * - false if the next Block or Stream matching the mode was 625c917796cSXin LI * found. *iter is updated (success). 62681ad8388SMartin Matuska */ 62781ad8388SMartin Matuska extern LZMA_API(lzma_bool) lzma_index_iter_next( 62881ad8388SMartin Matuska lzma_index_iter *iter, lzma_index_iter_mode mode) 62981ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 63081ad8388SMartin Matuska 63181ad8388SMartin Matuska 63281ad8388SMartin Matuska /** 63381ad8388SMartin Matuska * \brief Locate a Block 63481ad8388SMartin Matuska * 63581ad8388SMartin Matuska * If it is possible to seek in the .xz file, it is possible to parse 63681ad8388SMartin Matuska * the Index field(s) and use lzma_index_iter_locate() to do random-access 63781ad8388SMartin Matuska * reading with granularity of Block size. 63881ad8388SMartin Matuska * 63981ad8388SMartin Matuska * If the target is smaller than the uncompressed size of the Stream (can be 64081ad8388SMartin Matuska * checked with lzma_index_uncompressed_size()): 64181ad8388SMartin Matuska * - Information about the Stream and Block containing the requested 64281ad8388SMartin Matuska * uncompressed offset is stored into *iter. 64381ad8388SMartin Matuska * - Internal state of the iterator is adjusted so that 64481ad8388SMartin Matuska * lzma_index_iter_next() can be used to read subsequent Blocks or Streams. 64581ad8388SMartin Matuska * 646c917796cSXin LI * If the target is greater than the uncompressed size of the Stream, *iter 647c917796cSXin LI * is not modified. 648c917796cSXin LI * 649c917796cSXin LI * \param iter Iterator that was earlier initialized with 650c917796cSXin LI * lzma_index_iter_init(). 651c917796cSXin LI * \param target Uncompressed target offset which the caller would 652c917796cSXin LI * like to locate from the Stream 653c917796cSXin LI * 654c917796cSXin LI * \return lzma_bool: 655c917796cSXin LI * - true if the target is greater than or equal to the 656c917796cSXin LI * uncompressed size of the Stream (failure) 657c917796cSXin LI * - false if the target is smaller than the uncompressed size 658c917796cSXin LI * of the Stream (success) 65981ad8388SMartin Matuska */ 66081ad8388SMartin Matuska extern LZMA_API(lzma_bool) lzma_index_iter_locate( 66181ad8388SMartin Matuska lzma_index_iter *iter, lzma_vli target) lzma_nothrow; 66281ad8388SMartin Matuska 66381ad8388SMartin Matuska 66481ad8388SMartin Matuska /** 66581ad8388SMartin Matuska * \brief Concatenate lzma_indexes 66681ad8388SMartin Matuska * 66781ad8388SMartin Matuska * Concatenating lzma_indexes is useful when doing random-access reading in 66881ad8388SMartin Matuska * multi-Stream .xz file, or when combining multiple Streams into single 66981ad8388SMartin Matuska * Stream. 67081ad8388SMartin Matuska * 671c917796cSXin LI * \param[out] dest lzma_index after which src is appended 67281ad8388SMartin Matuska * \param src lzma_index to be appended after dest. If this 67381ad8388SMartin Matuska * function succeeds, the memory allocated for src 67481ad8388SMartin Matuska * is freed or moved to be part of dest, and all 67581ad8388SMartin Matuska * iterators pointing to src will become invalid. 676c917796cSXin LI * \param allocator lzma_allocator for custom allocator functions. 677c917796cSXin LI * Set to NULL to use malloc() and free(). 67881ad8388SMartin Matuska * 679c917796cSXin LI * \return Possible lzma_ret values: 680c917796cSXin LI * - LZMA_OK: lzma_indexes were concatenated successfully. 68181ad8388SMartin Matuska * src is now a dangling pointer. 68281ad8388SMartin Matuska * - LZMA_DATA_ERROR: *dest would grow too big. 68381ad8388SMartin Matuska * - LZMA_MEM_ERROR 68481ad8388SMartin Matuska * - LZMA_PROG_ERROR 68581ad8388SMartin Matuska */ 68653200025SRui Paulo extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src, 68753200025SRui Paulo const lzma_allocator *allocator) 68881ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 68981ad8388SMartin Matuska 69081ad8388SMartin Matuska 69181ad8388SMartin Matuska /** 69281ad8388SMartin Matuska * \brief Duplicate lzma_index 69381ad8388SMartin Matuska * 694c917796cSXin LI * \param i Pointer to lzma_index structure to be duplicated 695c917796cSXin LI * \param allocator lzma_allocator for custom allocator functions. 696c917796cSXin LI * Set to NULL to use malloc() and free(). 697c917796cSXin LI * 69881ad8388SMartin Matuska * \return A copy of the lzma_index, or NULL if memory allocation failed. 69981ad8388SMartin Matuska */ 70081ad8388SMartin Matuska extern LZMA_API(lzma_index *) lzma_index_dup( 70153200025SRui Paulo const lzma_index *i, const lzma_allocator *allocator) 70281ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 70381ad8388SMartin Matuska 70481ad8388SMartin Matuska 70581ad8388SMartin Matuska /** 70681ad8388SMartin Matuska * \brief Initialize .xz Index encoder 70781ad8388SMartin Matuska * 70881ad8388SMartin Matuska * \param strm Pointer to properly prepared lzma_stream 70981ad8388SMartin Matuska * \param i Pointer to lzma_index which should be encoded. 71081ad8388SMartin Matuska * 711*3b35e7eeSXin LI * The valid 'action' values for lzma_code() are LZMA_RUN and LZMA_FINISH. 712b71a5db3SXin LI * It is enough to use only one of them (you can choose freely). 71381ad8388SMartin Matuska * 714c917796cSXin LI * \return Possible lzma_ret values: 715c917796cSXin LI * - LZMA_OK: Initialization succeeded, continue with lzma_code(). 71681ad8388SMartin Matuska * - LZMA_MEM_ERROR 71781ad8388SMartin Matuska * - LZMA_PROG_ERROR 71881ad8388SMartin Matuska */ 71981ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_encoder( 72081ad8388SMartin Matuska lzma_stream *strm, const lzma_index *i) 72181ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 72281ad8388SMartin Matuska 72381ad8388SMartin Matuska 72481ad8388SMartin Matuska /** 72581ad8388SMartin Matuska * \brief Initialize .xz Index decoder 72681ad8388SMartin Matuska * 72781ad8388SMartin Matuska * \param strm Pointer to properly prepared lzma_stream 728c917796cSXin LI * \param[out] i The decoded Index will be made available via 72981ad8388SMartin Matuska * this pointer. Initially this function will 73081ad8388SMartin Matuska * set *i to NULL (the old value is ignored). If 73181ad8388SMartin Matuska * decoding succeeds (lzma_code() returns 73281ad8388SMartin Matuska * LZMA_STREAM_END), *i will be set to point 73381ad8388SMartin Matuska * to a new lzma_index, which the application 73481ad8388SMartin Matuska * has to later free with lzma_index_end(). 73581ad8388SMartin Matuska * \param memlimit How much memory the resulting lzma_index is 736b71a5db3SXin LI * allowed to require. liblzma 5.2.3 and earlier 737b71a5db3SXin LI * don't allow 0 here and return LZMA_PROG_ERROR; 738b71a5db3SXin LI * later versions treat 0 as if 1 had been specified. 73981ad8388SMartin Matuska * 740*3b35e7eeSXin LI * Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. 741b71a5db3SXin LI * There is no need to use LZMA_FINISH, but it's allowed because it may 742b71a5db3SXin LI * simplify certain types of applications. 74381ad8388SMartin Matuska * 744c917796cSXin LI * \return Possible lzma_ret values: 745c917796cSXin LI * - LZMA_OK: Initialization succeeded, continue with lzma_code(). 74681ad8388SMartin Matuska * - LZMA_MEM_ERROR 74781ad8388SMartin Matuska * - LZMA_PROG_ERROR 748b71a5db3SXin LI * 749c917796cSXin LI * \note liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here 750b71a5db3SXin LI * but that error code has never been possible from this 751b71a5db3SXin LI * initialization function. 75281ad8388SMartin Matuska */ 75381ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_decoder( 75481ad8388SMartin Matuska lzma_stream *strm, lzma_index **i, uint64_t memlimit) 75581ad8388SMartin Matuska lzma_nothrow lzma_attr_warn_unused_result; 75681ad8388SMartin Matuska 75781ad8388SMartin Matuska 75881ad8388SMartin Matuska /** 75981ad8388SMartin Matuska * \brief Single-call .xz Index encoder 76081ad8388SMartin Matuska * 761c917796cSXin LI * \note This function doesn't take allocator argument since all 762c917796cSXin LI * the internal data is allocated on stack. 763c917796cSXin LI * 76481ad8388SMartin Matuska * \param i lzma_index to be encoded 765c917796cSXin LI * \param[out] out Beginning of the output buffer 766c917796cSXin LI * \param[out] out_pos The next byte will be written to out[*out_pos]. 76781ad8388SMartin Matuska * *out_pos is updated only if encoding succeeds. 76881ad8388SMartin Matuska * \param out_size Size of the out buffer; the first byte into 76981ad8388SMartin Matuska * which no data is written to is out[out_size]. 77081ad8388SMartin Matuska * 771c917796cSXin LI * \return Possible lzma_ret values: 772c917796cSXin LI * - LZMA_OK: Encoding was successful. 77381ad8388SMartin Matuska * - LZMA_BUF_ERROR: Output buffer is too small. Use 77481ad8388SMartin Matuska * lzma_index_size() to find out how much output 77581ad8388SMartin Matuska * space is needed. 77681ad8388SMartin Matuska * - LZMA_PROG_ERROR 77781ad8388SMartin Matuska * 77881ad8388SMartin Matuska */ 77981ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i, 78081ad8388SMartin Matuska uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; 78181ad8388SMartin Matuska 78281ad8388SMartin Matuska 78381ad8388SMartin Matuska /** 78481ad8388SMartin Matuska * \brief Single-call .xz Index decoder 78581ad8388SMartin Matuska * 786c917796cSXin LI * \param[out] i If decoding succeeds, *i will point to a new 78781ad8388SMartin Matuska * lzma_index, which the application has to 78881ad8388SMartin Matuska * later free with lzma_index_end(). If an error 78981ad8388SMartin Matuska * occurs, *i will be NULL. The old value of *i 79081ad8388SMartin Matuska * is always ignored and thus doesn't need to be 79181ad8388SMartin Matuska * initialized by the caller. 792c917796cSXin LI * \param[out] memlimit Pointer to how much memory the resulting 79381ad8388SMartin Matuska * lzma_index is allowed to require. The value 79481ad8388SMartin Matuska * pointed by this pointer is modified if and only 79581ad8388SMartin Matuska * if LZMA_MEMLIMIT_ERROR is returned. 796c917796cSXin LI * \param allocator lzma_allocator for custom allocator functions. 797c917796cSXin LI * Set to NULL to use malloc() and free(). 79881ad8388SMartin Matuska * \param in Beginning of the input buffer 79981ad8388SMartin Matuska * \param in_pos The next byte will be read from in[*in_pos]. 80081ad8388SMartin Matuska * *in_pos is updated only if decoding succeeds. 80181ad8388SMartin Matuska * \param in_size Size of the input buffer; the first byte that 80281ad8388SMartin Matuska * won't be read is in[in_size]. 80381ad8388SMartin Matuska * 804c917796cSXin LI * \return Possible lzma_ret values: 805c917796cSXin LI * - LZMA_OK: Decoding was successful. 80681ad8388SMartin Matuska * - LZMA_MEM_ERROR 80781ad8388SMartin Matuska * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 80881ad8388SMartin Matuska * The minimum required memlimit value was stored to *memlimit. 80981ad8388SMartin Matuska * - LZMA_DATA_ERROR 81081ad8388SMartin Matuska * - LZMA_PROG_ERROR 81181ad8388SMartin Matuska */ 81281ad8388SMartin Matuska extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i, 81353200025SRui Paulo uint64_t *memlimit, const lzma_allocator *allocator, 81481ad8388SMartin Matuska const uint8_t *in, size_t *in_pos, size_t in_size) 81581ad8388SMartin Matuska lzma_nothrow; 81673ed8e77SXin LI 81773ed8e77SXin LI 81873ed8e77SXin LI /** 81973ed8e77SXin LI * \brief Initialize a .xz file information decoder 82073ed8e77SXin LI * 82173ed8e77SXin LI * This decoder decodes the Stream Header, Stream Footer, Index, and 82273ed8e77SXin LI * Stream Padding field(s) from the input .xz file and stores the resulting 82373ed8e77SXin LI * combined index in *dest_index. This information can be used to get the 82473ed8e77SXin LI * uncompressed file size with lzma_index_uncompressed_size(*dest_index) or, 82573ed8e77SXin LI * for example, to implement random access reading by locating the Blocks 82673ed8e77SXin LI * in the Streams. 82773ed8e77SXin LI * 82873ed8e77SXin LI * To get the required information from the .xz file, lzma_code() may ask 82973ed8e77SXin LI * the application to seek in the input file by returning LZMA_SEEK_NEEDED 83073ed8e77SXin LI * and having the target file position specified in lzma_stream.seek_pos. 83173ed8e77SXin LI * The number of seeks required depends on the input file and how big buffers 83273ed8e77SXin LI * the application provides. When possible, the decoder will seek backward 83373ed8e77SXin LI * and forward in the given buffer to avoid useless seek requests. Thus, if 83473ed8e77SXin LI * the application provides the whole file at once, no external seeking will 83573ed8e77SXin LI * be required (that is, lzma_code() won't return LZMA_SEEK_NEEDED). 83673ed8e77SXin LI * 83773ed8e77SXin LI * The value in lzma_stream.total_in can be used to estimate how much data 83873ed8e77SXin LI * liblzma had to read to get the file information. However, due to seeking 83973ed8e77SXin LI * and the way total_in is updated, the value of total_in will be somewhat 84073ed8e77SXin LI * inaccurate (a little too big). Thus, total_in is a good estimate but don't 84173ed8e77SXin LI * expect to see the same exact value for the same file if you change the 84273ed8e77SXin LI * input buffer size or switch to a different liblzma version. 84373ed8e77SXin LI * 844*3b35e7eeSXin LI * Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. 84573ed8e77SXin LI * You only need to use LZMA_RUN; LZMA_FINISH is only supported because it 84673ed8e77SXin LI * might be convenient for some applications. If you use LZMA_FINISH and if 847*3b35e7eeSXin LI * lzma_code() asks the application to seek, remember to reset 'action' back 84873ed8e77SXin LI * to LZMA_RUN unless you hit the end of the file again. 84973ed8e77SXin LI * 85073ed8e77SXin LI * Possible return values from lzma_code(): 85173ed8e77SXin LI * - LZMA_OK: All OK so far, more input needed 85273ed8e77SXin LI * - LZMA_SEEK_NEEDED: Provide more input starting from the absolute 85373ed8e77SXin LI * file position strm->seek_pos 85473ed8e77SXin LI * - LZMA_STREAM_END: Decoding was successful, *dest_index has been set 85573ed8e77SXin LI * - LZMA_FORMAT_ERROR: The input file is not in the .xz format (the 85673ed8e77SXin LI * expected magic bytes were not found from the beginning of the file) 85773ed8e77SXin LI * - LZMA_OPTIONS_ERROR: File looks valid but contains headers that aren't 85873ed8e77SXin LI * supported by this version of liblzma 85973ed8e77SXin LI * - LZMA_DATA_ERROR: File is corrupt 86073ed8e77SXin LI * - LZMA_BUF_ERROR 86173ed8e77SXin LI * - LZMA_MEM_ERROR 86273ed8e77SXin LI * - LZMA_MEMLIMIT_ERROR 86373ed8e77SXin LI * - LZMA_PROG_ERROR 86473ed8e77SXin LI * 865c917796cSXin LI * \param strm Pointer to a properly prepared lzma_stream 866c917796cSXin LI * \param[out] dest_index Pointer to a pointer where the decoder will put 867c917796cSXin LI * the decoded lzma_index. The old value 868c917796cSXin LI * of *dest_index is ignored (not freed). 869c917796cSXin LI * \param memlimit How much memory the resulting lzma_index is 870c917796cSXin LI * allowed to require. Use UINT64_MAX to 871c917796cSXin LI * effectively disable the limiter. 872c917796cSXin LI * \param file_size Size of the input .xz file 873c917796cSXin LI * 874c917796cSXin LI * \return Possible lzma_ret values: 875c917796cSXin LI * - LZMA_OK 87673ed8e77SXin LI * - LZMA_MEM_ERROR 87773ed8e77SXin LI * - LZMA_PROG_ERROR 87873ed8e77SXin LI */ 87973ed8e77SXin LI extern LZMA_API(lzma_ret) lzma_file_info_decoder( 88073ed8e77SXin LI lzma_stream *strm, lzma_index **dest_index, 88173ed8e77SXin LI uint64_t memlimit, uint64_t file_size) 88273ed8e77SXin LI lzma_nothrow; 883