index.h revision 213700
1207753Smm/** 2207753Smm * \file lzma/index.h 3207753Smm * \brief Handling of .xz Index and related information 4207753Smm */ 5207753Smm 6207753Smm/* 7207753Smm * Author: Lasse Collin 8207753Smm * 9207753Smm * This file has been put into the public domain. 10207753Smm * You can do whatever you want with this file. 11207753Smm * 12207753Smm * See ../lzma.h for information about liblzma as a whole. 13207753Smm */ 14207753Smm 15207753Smm#ifndef LZMA_H_INTERNAL 16207753Smm# error Never include this file directly. Use <lzma.h> instead. 17207753Smm#endif 18207753Smm 19207753Smm 20207753Smm/** 21207753Smm * \brief Opaque data type to hold the Index(es) and other information 22207753Smm * 23207753Smm * lzma_index often holds just one .xz Index and possibly the Stream Flags 24207753Smm * of the same Stream and size of the Stream Padding field. However, 25207753Smm * multiple lzma_indexes can be concatenated with lzma_index_cat() and then 26207753Smm * there may be information about multiple Streams in the same lzma_index. 27207753Smm * 28207753Smm * Notes about thread safety: Only one thread may modify lzma_index at 29207753Smm * a time. All functions that take non-const pointer to lzma_index 30207753Smm * modify it. As long as no thread is modifying the lzma_index, getting 31207753Smm * information from the same lzma_index can be done from multiple threads 32207753Smm * at the same time with functions that take a const pointer to 33207753Smm * lzma_index or use lzma_index_iter. The same iterator must be used 34207753Smm * only by one thread at a time, of course, but there can be as many 35207753Smm * iterators for the same lzma_index as needed. 36207753Smm */ 37207753Smmtypedef struct lzma_index_s lzma_index; 38207753Smm 39207753Smm 40207753Smm/** 41207753Smm * \brief Iterator to get information about Blocks and Streams 42207753Smm */ 43207753Smmtypedef struct { 44207753Smm struct { 45207753Smm /** 46207753Smm * \brief Pointer to Stream Flags 47207753Smm * 48207753Smm * This is NULL if Stream Flags have not been set for 49207753Smm * this Stream with lzma_index_stream_flags(). 50207753Smm */ 51207753Smm const lzma_stream_flags *flags; 52207753Smm 53207753Smm const void *reserved_ptr1; 54207753Smm const void *reserved_ptr2; 55207753Smm const void *reserved_ptr3; 56207753Smm 57207753Smm /** 58207753Smm * \brief Stream number in the lzma_index 59207753Smm * 60207753Smm * The first Stream is 1. 61207753Smm */ 62207753Smm lzma_vli number; 63207753Smm 64207753Smm /** 65207753Smm * \brief Number of Blocks in the Stream 66207753Smm * 67207753Smm * If this is zero, the block structure below has 68207753Smm * undefined values. 69207753Smm */ 70207753Smm lzma_vli block_count; 71207753Smm 72207753Smm /** 73207753Smm * \brief Compressed start offset of this Stream 74207753Smm * 75207753Smm * The offset is relative to the beginning of the lzma_index 76207753Smm * (i.e. usually the beginning of the .xz file). 77207753Smm */ 78207753Smm lzma_vli compressed_offset; 79207753Smm 80207753Smm /** 81207753Smm * \brief Uncompressed start offset of this Stream 82207753Smm * 83207753Smm * The offset is relative to the beginning of the lzma_index 84207753Smm * (i.e. usually the beginning of the .xz file). 85207753Smm */ 86207753Smm lzma_vli uncompressed_offset; 87207753Smm 88207753Smm /** 89207753Smm * \brief Compressed size of this Stream 90207753Smm * 91207753Smm * This includes all headers except the possible 92207753Smm * Stream Padding after this Stream. 93207753Smm */ 94207753Smm lzma_vli compressed_size; 95207753Smm 96207753Smm /** 97207753Smm * \brief Uncompressed size of this Stream 98207753Smm */ 99207753Smm lzma_vli uncompressed_size; 100207753Smm 101207753Smm /** 102207753Smm * \brief Size of Stream Padding after this Stream 103207753Smm * 104207753Smm * If it hasn't been set with lzma_index_stream_padding(), 105207753Smm * this defaults to zero. Stream Padding is always 106207753Smm * a multiple of four bytes. 107207753Smm */ 108207753Smm lzma_vli padding; 109207753Smm 110207753Smm lzma_vli reserved_vli1; 111207753Smm lzma_vli reserved_vli2; 112207753Smm lzma_vli reserved_vli3; 113207753Smm lzma_vli reserved_vli4; 114207753Smm } stream; 115207753Smm 116207753Smm struct { 117207753Smm /** 118207753Smm * \brief Block number in the file 119207753Smm * 120207753Smm * The first Block is 1. 121207753Smm */ 122207753Smm lzma_vli number_in_file; 123207753Smm 124207753Smm /** 125207753Smm * \brief Compressed start offset of this Block 126207753Smm * 127207753Smm * This offset is relative to the beginning of the 128207753Smm * lzma_index (i.e. usually the beginning of the .xz file). 129207753Smm * Normally this is where you should seek in the .xz file 130207753Smm * to start decompressing this Block. 131207753Smm */ 132207753Smm lzma_vli compressed_file_offset; 133207753Smm 134207753Smm /** 135207753Smm * \brief Uncompressed start offset of this Block 136207753Smm * 137207753Smm * This offset is relative to the beginning of the lzma_index 138207753Smm * (i.e. usually the beginning of the .xz file). 139207753Smm */ 140207753Smm lzma_vli uncompressed_file_offset; 141207753Smm 142207753Smm /** 143207753Smm * \brief Block number in this Stream 144207753Smm * 145207753Smm * The first Block is 1. 146207753Smm */ 147207753Smm lzma_vli number_in_stream; 148207753Smm 149207753Smm /** 150207753Smm * \brief Compressed start offset of this Block 151207753Smm * 152207753Smm * This offset is relative to the beginning of the Stream 153207753Smm * containing this Block. 154207753Smm */ 155207753Smm lzma_vli compressed_stream_offset; 156207753Smm 157207753Smm /** 158207753Smm * \brief Uncompressed start offset of this Block 159207753Smm * 160207753Smm * This offset is relative to the beginning of the Stream 161207753Smm * containing this Block. 162207753Smm */ 163207753Smm lzma_vli uncompressed_stream_offset; 164207753Smm 165207753Smm /** 166207753Smm * \brief Uncompressed size of this Block 167207753Smm * 168207753Smm * You should pass this to the Block decoder if you will 169207753Smm * decode this Block. 170207753Smm * 171207753Smm * When doing random-access reading, it is possible that 172207753Smm * the target offset is not exactly at Block boundary. One 173207753Smm * will need to compare the target offset against 174207753Smm * uncompressed_file_offset or uncompressed_stream_offset, 175207753Smm * and possibly decode and throw away some amount of data 176207753Smm * before reaching the target offset. 177207753Smm */ 178207753Smm lzma_vli uncompressed_size; 179207753Smm 180207753Smm /** 181207753Smm * \brief Unpadded size of this Block 182207753Smm * 183207753Smm * You should pass this to the Block decoder if you will 184207753Smm * decode this Block. 185207753Smm */ 186207753Smm lzma_vli unpadded_size; 187207753Smm 188207753Smm /** 189207753Smm * \brief Total compressed size 190207753Smm * 191207753Smm * This includes all headers and padding in this Block. 192207753Smm * This is useful if you need to know how many bytes 193207753Smm * the Block decoder will actually read. 194207753Smm */ 195207753Smm lzma_vli total_size; 196207753Smm 197207753Smm lzma_vli reserved_vli1; 198207753Smm lzma_vli reserved_vli2; 199207753Smm lzma_vli reserved_vli3; 200207753Smm lzma_vli reserved_vli4; 201207753Smm 202207753Smm const void *reserved_ptr1; 203207753Smm const void *reserved_ptr2; 204207753Smm const void *reserved_ptr3; 205207753Smm const void *reserved_ptr4; 206207753Smm } block; 207207753Smm 208207753Smm /* 209207753Smm * Internal data which is used to store the state of the iterator. 210207753Smm * The exact format may vary between liblzma versions, so don't 211207753Smm * touch these in any way. 212207753Smm */ 213207753Smm union { 214207753Smm const void *p; 215207753Smm size_t s; 216207753Smm lzma_vli v; 217207753Smm } internal[6]; 218207753Smm} lzma_index_iter; 219207753Smm 220207753Smm 221207753Smm/** 222207753Smm * \brief Operation mode for lzma_index_iter_next() 223207753Smm */ 224207753Smmtypedef enum { 225207753Smm LZMA_INDEX_ITER_ANY = 0, 226207753Smm /**< 227207753Smm * \brief Get the next Block or Stream 228207753Smm * 229207753Smm * Go to the next Block if the current Stream has at least 230207753Smm * one Block left. Otherwise go to the next Stream even if 231207753Smm * it has no Blocks. If the Stream has no Blocks 232207753Smm * (lzma_index_iter.stream.block_count == 0), 233207753Smm * lzma_index_iter.block will have undefined values. 234207753Smm */ 235207753Smm 236207753Smm LZMA_INDEX_ITER_STREAM = 1, 237207753Smm /**< 238207753Smm * \brief Get the next Stream 239207753Smm * 240207753Smm * Go to the next Stream even if the current Stream has 241207753Smm * unread Blocks left. If the next Stream has at least one 242207753Smm * Block, the iterator will point to the first Block. 243207753Smm * If there are no Blocks, lzma_index_iter.block will have 244207753Smm * undefined values. 245207753Smm */ 246207753Smm 247207753Smm LZMA_INDEX_ITER_BLOCK = 2, 248207753Smm /**< 249207753Smm * \brief Get the next Block 250207753Smm * 251207753Smm * Go to the next Block if the current Stream has at least 252207753Smm * one Block left. If the current Stream has no Blocks left, 253207753Smm * the next Stream with at least one Block is located and 254207753Smm * the iterator will be made to point to the first Block of 255207753Smm * that Stream. 256207753Smm */ 257207753Smm 258207753Smm LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3 259207753Smm /**< 260207753Smm * \brief Get the next non-empty Block 261207753Smm * 262207753Smm * This is like LZMA_INDEX_ITER_BLOCK except that it will 263207753Smm * skip Blocks whose Uncompressed Size is zero. 264207753Smm */ 265207753Smm 266207753Smm} lzma_index_iter_mode; 267207753Smm 268207753Smm 269207753Smm/** 270207753Smm * \brief Calculate memory usage of lzma_index 271207753Smm * 272207753Smm * On disk, the size of the Index field depends on both the number of Records 273207753Smm * stored and how big values the Records store (due to variable-length integer 274207753Smm * encoding). When the Index is kept in lzma_index structure, the memory usage 275207753Smm * depends only on the number of Records/Blocks stored in the Index(es), and 276207753Smm * in case of concatenated lzma_indexes, the number of Streams. The size in 277207753Smm * RAM is almost always significantly bigger than in the encoded form on disk. 278207753Smm * 279207753Smm * This function calculates an approximate amount of memory needed hold 280207753Smm * the given number of Streams and Blocks in lzma_index structure. This 281207753Smm * value may vary between CPU architectures and also between liblzma versions 282207753Smm * if the internal implementation is modified. 283207753Smm */ 284207753Smmextern LZMA_API(uint64_t) lzma_index_memusage( 285207753Smm lzma_vli streams, lzma_vli blocks) lzma_nothrow; 286207753Smm 287207753Smm 288207753Smm/** 289207753Smm * \brief Calculate the memory usage of an existing lzma_index 290207753Smm * 291207753Smm * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), 292207753Smm * lzma_index_block_count(i)). 293207753Smm */ 294207753Smmextern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) 295207753Smm lzma_nothrow; 296207753Smm 297207753Smm 298207753Smm/** 299207753Smm * \brief Allocate and initialize a new lzma_index structure 300207753Smm * 301207753Smm * \return On success, a pointer to an empty initialized lzma_index is 302207753Smm * returned. If allocation fails, NULL is returned. 303207753Smm */ 304207753Smmextern LZMA_API(lzma_index *) lzma_index_init(lzma_allocator *allocator) 305207753Smm lzma_nothrow; 306207753Smm 307207753Smm 308207753Smm/** 309207753Smm * \brief Deallocate lzma_index 310207753Smm * 311207753Smm * If i is NULL, this does nothing. 312207753Smm */ 313207753Smmextern LZMA_API(void) lzma_index_end(lzma_index *i, lzma_allocator *allocator) 314207753Smm lzma_nothrow; 315207753Smm 316207753Smm 317207753Smm/** 318207753Smm * \brief Add a new Block to lzma_index 319207753Smm * 320207753Smm * \param i Pointer to a lzma_index structure 321207753Smm * \param allocator Pointer to lzma_allocator, or NULL to 322207753Smm * use malloc() 323207753Smm * \param unpadded_size Unpadded Size of a Block. This can be 324207753Smm * calculated with lzma_block_unpadded_size() 325207753Smm * after encoding or decoding the Block. 326207753Smm * \param uncompressed_size Uncompressed Size of a Block. This can be 327207753Smm * taken directly from lzma_block structure 328207753Smm * after encoding or decoding the Block. 329207753Smm * 330207753Smm * Appending a new Block does not invalidate iterators. For example, 331207753Smm * if an iterator was pointing to the end of the lzma_index, after 332207753Smm * lzma_index_append() it is possible to read the next Block with 333207753Smm * an existing iterator. 334207753Smm * 335207753Smm * \return - LZMA_OK 336207753Smm * - LZMA_MEM_ERROR 337207753Smm * - LZMA_DATA_ERROR: Compressed or uncompressed size of the 338207753Smm * Stream or size of the Index field would grow too big. 339207753Smm * - LZMA_PROG_ERROR 340207753Smm */ 341207753Smmextern LZMA_API(lzma_ret) lzma_index_append( 342207753Smm lzma_index *i, lzma_allocator *allocator, 343207753Smm lzma_vli unpadded_size, lzma_vli uncompressed_size) 344207753Smm lzma_nothrow lzma_attr_warn_unused_result; 345207753Smm 346207753Smm 347207753Smm/** 348207753Smm * \brief Set the Stream Flags 349207753Smm * 350207753Smm * Set the Stream Flags of the last (and typically the only) Stream 351207753Smm * in lzma_index. This can be useful when reading information from the 352207753Smm * lzma_index, because to decode Blocks, knowing the integrity check type 353207753Smm * is needed. 354207753Smm * 355207753Smm * The given Stream Flags are copied into internal preallocated structure 356207753Smm * in the lzma_index, thus the caller doesn't need to keep the *stream_flags 357207753Smm * available after calling this function. 358207753Smm * 359207753Smm * \return - LZMA_OK 360207753Smm * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version. 361207753Smm * - LZMA_PROG_ERROR 362207753Smm */ 363207753Smmextern LZMA_API(lzma_ret) lzma_index_stream_flags( 364207753Smm lzma_index *i, const lzma_stream_flags *stream_flags) 365207753Smm lzma_nothrow lzma_attr_warn_unused_result; 366207753Smm 367207753Smm 368207753Smm/** 369207753Smm * \brief Get the types of integrity Checks 370207753Smm * 371213700Smm * If lzma_index_stream_flags() is used to set the Stream Flags for 372207753Smm * every Stream, lzma_index_checks() can be used to get a bitmask to 373207753Smm * indicate which Check types have been used. It can be useful e.g. if 374207753Smm * showing the Check types to the user. 375207753Smm * 376207753Smm * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10. 377207753Smm */ 378207753Smmextern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i) 379207753Smm lzma_nothrow lzma_attr_pure; 380207753Smm 381207753Smm 382207753Smm/** 383207753Smm * \brief Set the amount of Stream Padding 384207753Smm * 385207753Smm * Set the amount of Stream Padding of the last (and typically the only) 386207753Smm * Stream in the lzma_index. This is needed when planning to do random-access 387207753Smm * reading within multiple concatenated Streams. 388207753Smm * 389207753Smm * By default, the amount of Stream Padding is assumed to be zero bytes. 390207753Smm * 391207753Smm * \return - LZMA_OK 392207753Smm * - LZMA_DATA_ERROR: The file size would grow too big. 393207753Smm * - LZMA_PROG_ERROR 394207753Smm */ 395207753Smmextern LZMA_API(lzma_ret) lzma_index_stream_padding( 396207753Smm lzma_index *i, lzma_vli stream_padding) 397207753Smm lzma_nothrow lzma_attr_warn_unused_result; 398207753Smm 399207753Smm 400207753Smm/** 401207753Smm * \brief Get the number of Streams 402207753Smm */ 403207753Smmextern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i) 404207753Smm lzma_nothrow lzma_attr_pure; 405207753Smm 406207753Smm 407207753Smm/** 408207753Smm * \brief Get the number of Blocks 409207753Smm * 410207753Smm * This returns the total number of Blocks in lzma_index. To get number 411207753Smm * of Blocks in individual Streams, use lzma_index_iter. 412207753Smm */ 413207753Smmextern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i) 414207753Smm lzma_nothrow lzma_attr_pure; 415207753Smm 416207753Smm 417207753Smm/** 418207753Smm * \brief Get the size of the Index field as bytes 419207753Smm * 420207753Smm * This is needed to verify the Backward Size field in the Stream Footer. 421207753Smm */ 422207753Smmextern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i) 423207753Smm lzma_nothrow lzma_attr_pure; 424207753Smm 425207753Smm 426207753Smm/** 427207753Smm * \brief Get the total size of the Stream 428207753Smm * 429207753Smm * If multiple lzma_indexes have been combined, this works as if the Blocks 430207753Smm * were in a single Stream. This is useful if you are going to combine 431207753Smm * Blocks from multiple Streams into a single new Stream. 432207753Smm */ 433207753Smmextern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i) 434207753Smm lzma_nothrow lzma_attr_pure; 435207753Smm 436207753Smm 437207753Smm/** 438207753Smm * \brief Get the total size of the Blocks 439207753Smm * 440207753Smm * This doesn't include the Stream Header, Stream Footer, Stream Padding, 441207753Smm * or Index fields. 442207753Smm */ 443207753Smmextern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i) 444207753Smm lzma_nothrow lzma_attr_pure; 445207753Smm 446207753Smm 447207753Smm/** 448207753Smm * \brief Get the total size of the file 449207753Smm * 450207753Smm * When no lzma_indexes have been combined with lzma_index_cat() and there is 451207753Smm * no Stream Padding, this function is identical to lzma_index_stream_size(). 452207753Smm * If multiple lzma_indexes have been combined, this includes also the headers 453207753Smm * of each separate Stream and the possible Stream Padding fields. 454207753Smm */ 455207753Smmextern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i) 456207753Smm lzma_nothrow lzma_attr_pure; 457207753Smm 458207753Smm 459207753Smm/** 460207753Smm * \brief Get the uncompressed size of the file 461207753Smm */ 462207753Smmextern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i) 463207753Smm lzma_nothrow lzma_attr_pure; 464207753Smm 465207753Smm 466207753Smm/** 467207753Smm * \brief Initialize an iterator 468207753Smm * 469207753Smm * \param iter Pointer to a lzma_index_iter structure 470207753Smm * \param i lzma_index to which the iterator will be associated 471207753Smm * 472207753Smm * This function associates the iterator with the given lzma_index, and calls 473207753Smm * lzma_index_iter_rewind() on the iterator. 474207753Smm * 475207753Smm * This function doesn't allocate any memory, thus there is no 476207753Smm * lzma_index_iter_end(). The iterator is valid as long as the 477207753Smm * associated lzma_index is valid, that is, until lzma_index_end() or 478207753Smm * using it as source in lzma_index_cat(). Specifically, lzma_index doesn't 479207753Smm * become invalid if new Blocks are added to it with lzma_index_append() or 480207753Smm * if it is used as the destination in lzma_index_cat(). 481207753Smm * 482207753Smm * It is safe to make copies of an initialized lzma_index_iter, for example, 483207753Smm * to easily restart reading at some particular position. 484207753Smm */ 485207753Smmextern LZMA_API(void) lzma_index_iter_init( 486207753Smm lzma_index_iter *iter, const lzma_index *i) lzma_nothrow; 487207753Smm 488207753Smm 489207753Smm/** 490207753Smm * \brief Rewind the iterator 491207753Smm * 492207753Smm * Rewind the iterator so that next call to lzma_index_iter_next() will 493207753Smm * return the first Block or Stream. 494207753Smm */ 495207753Smmextern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter) 496207753Smm lzma_nothrow; 497207753Smm 498207753Smm 499207753Smm/** 500207753Smm * \brief Get the next Block or Stream 501207753Smm * 502207753Smm * \param iter Iterator initialized with lzma_index_iter_init() 503207753Smm * \param mode Specify what kind of information the caller wants 504207753Smm * to get. See lzma_index_iter_mode for details. 505207753Smm * 506207753Smm * \return If next Block or Stream matching the mode was found, *iter 507207753Smm * is updated and this function returns false. If no Block or 508207753Smm * Stream matching the mode is found, *iter is not modified 509207753Smm * and this function returns true. If mode is set to an unknown 510207753Smm * value, *iter is not modified and this function returns true. 511207753Smm */ 512207753Smmextern LZMA_API(lzma_bool) lzma_index_iter_next( 513207753Smm lzma_index_iter *iter, lzma_index_iter_mode mode) 514207753Smm lzma_nothrow lzma_attr_warn_unused_result; 515207753Smm 516207753Smm 517207753Smm/** 518207753Smm * \brief Locate a Block 519207753Smm * 520207753Smm * If it is possible to seek in the .xz file, it is possible to parse 521207753Smm * the Index field(s) and use lzma_index_iter_locate() to do random-access 522207753Smm * reading with granularity of Block size. 523207753Smm * 524207753Smm * \param iter Iterator that was earlier initialized with 525207753Smm * lzma_index_iter_init(). 526207753Smm * \param target Uncompressed target offset which the caller would 527207753Smm * like to locate from the Stream 528207753Smm * 529207753Smm * If the target is smaller than the uncompressed size of the Stream (can be 530207753Smm * checked with lzma_index_uncompressed_size()): 531207753Smm * - Information about the Stream and Block containing the requested 532207753Smm * uncompressed offset is stored into *iter. 533207753Smm * - Internal state of the iterator is adjusted so that 534207753Smm * lzma_index_iter_next() can be used to read subsequent Blocks or Streams. 535207753Smm * - This function returns false. 536207753Smm * 537207753Smm * If target is greater than the uncompressed size of the Stream, *iter 538207753Smm * is not modified, and this function returns true. 539207753Smm */ 540207753Smmextern LZMA_API(lzma_bool) lzma_index_iter_locate( 541207753Smm lzma_index_iter *iter, lzma_vli target) lzma_nothrow; 542207753Smm 543207753Smm 544207753Smm/** 545207753Smm * \brief Concatenate lzma_indexes 546207753Smm * 547207753Smm * Concatenating lzma_indexes is useful when doing random-access reading in 548207753Smm * multi-Stream .xz file, or when combining multiple Streams into single 549207753Smm * Stream. 550207753Smm * 551207753Smm * \param dest lzma_index after which src is appended 552207753Smm * \param src lzma_index to be appended after dest. If this 553207753Smm * function succeeds, the memory allocated for src 554207753Smm * is freed or moved to be part of dest, and all 555207753Smm * iterators pointing to src will become invalid. 556207753Smm * \param allocator Custom memory allocator; can be NULL to use 557207753Smm * malloc() and free(). 558207753Smm * 559207753Smm * \return - LZMA_OK: lzma_indexes were concatenated successfully. 560207753Smm * src is now a dangling pointer. 561207753Smm * - LZMA_DATA_ERROR: *dest would grow too big. 562207753Smm * - LZMA_MEM_ERROR 563207753Smm * - LZMA_PROG_ERROR 564207753Smm */ 565213700Smmextern LZMA_API(lzma_ret) lzma_index_cat( 566213700Smm lzma_index *dest, lzma_index *src, lzma_allocator *allocator) 567207753Smm lzma_nothrow lzma_attr_warn_unused_result; 568207753Smm 569207753Smm 570207753Smm/** 571207753Smm * \brief Duplicate lzma_index 572207753Smm * 573207753Smm * \return A copy of the lzma_index, or NULL if memory allocation failed. 574207753Smm */ 575207753Smmextern LZMA_API(lzma_index *) lzma_index_dup( 576207753Smm const lzma_index *i, lzma_allocator *allocator) 577207753Smm lzma_nothrow lzma_attr_warn_unused_result; 578207753Smm 579207753Smm 580207753Smm/** 581207753Smm * \brief Initialize .xz Index encoder 582207753Smm * 583207753Smm * \param strm Pointer to properly prepared lzma_stream 584207753Smm * \param i Pointer to lzma_index which should be encoded. 585207753Smm * 586207753Smm * The only valid action value for lzma_code() is LZMA_RUN. 587207753Smm * 588207753Smm * \return - LZMA_OK: Initialization succeeded, continue with lzma_code(). 589207753Smm * - LZMA_MEM_ERROR 590207753Smm * - LZMA_PROG_ERROR 591207753Smm */ 592207753Smmextern LZMA_API(lzma_ret) lzma_index_encoder( 593207753Smm lzma_stream *strm, const lzma_index *i) 594207753Smm lzma_nothrow lzma_attr_warn_unused_result; 595207753Smm 596207753Smm 597207753Smm/** 598207753Smm * \brief Initialize .xz Index decoder 599207753Smm * 600207753Smm * \param strm Pointer to properly prepared lzma_stream 601207753Smm * \param i The decoded Index will be made available via 602207753Smm * this pointer. Initially this function will 603207753Smm * set *i to NULL (the old value is ignored). If 604207753Smm * decoding succeeds (lzma_code() returns 605207753Smm * LZMA_STREAM_END), *i will be set to point 606207753Smm * to a new lzma_index, which the application 607207753Smm * has to later free with lzma_index_end(). 608207753Smm * \param memlimit How much memory the resulting lzma_index is 609207753Smm * allowed to require. 610207753Smm * 611207753Smm * The only valid action value for lzma_code() is LZMA_RUN. 612207753Smm * 613207753Smm * \return - LZMA_OK: Initialization succeeded, continue with lzma_code(). 614207753Smm * - LZMA_MEM_ERROR 615207753Smm * - LZMA_MEMLIMIT_ERROR 616207753Smm * - LZMA_PROG_ERROR 617207753Smm */ 618207753Smmextern LZMA_API(lzma_ret) lzma_index_decoder( 619207753Smm lzma_stream *strm, lzma_index **i, uint64_t memlimit) 620207753Smm lzma_nothrow lzma_attr_warn_unused_result; 621207753Smm 622207753Smm 623207753Smm/** 624207753Smm * \brief Single-call .xz Index encoder 625207753Smm * 626207753Smm * \param i lzma_index to be encoded 627207753Smm * \param out Beginning of the output buffer 628207753Smm * \param out_pos The next byte will be written to out[*out_pos]. 629207753Smm * *out_pos is updated only if encoding succeeds. 630207753Smm * \param out_size Size of the out buffer; the first byte into 631207753Smm * which no data is written to is out[out_size]. 632207753Smm * 633207753Smm * \return - LZMA_OK: Encoding was successful. 634207753Smm * - LZMA_BUF_ERROR: Output buffer is too small. Use 635207753Smm * lzma_index_size() to find out how much output 636207753Smm * space is needed. 637207753Smm * - LZMA_PROG_ERROR 638207753Smm * 639207753Smm * \note This function doesn't take allocator argument since all 640207753Smm * the internal data is allocated on stack. 641207753Smm */ 642207753Smmextern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i, 643207753Smm uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; 644207753Smm 645207753Smm 646207753Smm/** 647207753Smm * \brief Single-call .xz Index decoder 648207753Smm * 649207753Smm * \param i If decoding succeeds, *i will point to a new 650207753Smm * lzma_index, which the application has to 651207753Smm * later free with lzma_index_end(). If an error 652207753Smm * occurs, *i will be NULL. The old value of *i 653207753Smm * is always ignored and thus doesn't need to be 654207753Smm * initialized by the caller. 655207753Smm * \param memlimit Pointer to how much memory the resulting 656207753Smm * lzma_index is allowed to require. The value 657207753Smm * pointed by this pointer is modified if and only 658207753Smm * if LZMA_MEMLIMIT_ERROR is returned. 659207753Smm * \param allocator Pointer to lzma_allocator, or NULL to use malloc() 660207753Smm * \param in Beginning of the input buffer 661207753Smm * \param in_pos The next byte will be read from in[*in_pos]. 662207753Smm * *in_pos is updated only if decoding succeeds. 663207753Smm * \param in_size Size of the input buffer; the first byte that 664207753Smm * won't be read is in[in_size]. 665207753Smm * 666207753Smm * \return - LZMA_OK: Decoding was successful. 667207753Smm * - LZMA_MEM_ERROR 668207753Smm * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 669207753Smm * The minimum required memlimit value was stored to *memlimit. 670207753Smm * - LZMA_DATA_ERROR 671207753Smm * - LZMA_PROG_ERROR 672207753Smm */ 673207753Smmextern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i, 674207753Smm uint64_t *memlimit, lzma_allocator *allocator, 675207753Smm const uint8_t *in, size_t *in_pos, size_t in_size) 676207753Smm lzma_nothrow; 677