1*d2c16535SElliott Hughes /* SPDX-License-Identifier: 0BSD */ 2*d2c16535SElliott Hughes 3*d2c16535SElliott Hughes /* 4*d2c16535SElliott Hughes * Definitions for handling the .xz file format 5*d2c16535SElliott Hughes * 6*d2c16535SElliott Hughes * Author: Lasse Collin <[email protected]> 7*d2c16535SElliott Hughes */ 8*d2c16535SElliott Hughes 9*d2c16535SElliott Hughes #ifndef XZ_STREAM_H 10*d2c16535SElliott Hughes #define XZ_STREAM_H 11*d2c16535SElliott Hughes 12*d2c16535SElliott Hughes #if defined(__KERNEL__) && !XZ_INTERNAL_CRC32 13*d2c16535SElliott Hughes # include <linux/crc32.h> 14*d2c16535SElliott Hughes # undef crc32 15*d2c16535SElliott Hughes # define xz_crc32(buf, size, crc) \ 16*d2c16535SElliott Hughes (~crc32_le(~(uint32_t)(crc), buf, size)) 17*d2c16535SElliott Hughes #endif 18*d2c16535SElliott Hughes 19*d2c16535SElliott Hughes /* 20*d2c16535SElliott Hughes * See the .xz file format specification at 21*d2c16535SElliott Hughes * https://tukaani.org/xz/xz-file-format.txt 22*d2c16535SElliott Hughes * to understand the container format. 23*d2c16535SElliott Hughes */ 24*d2c16535SElliott Hughes 25*d2c16535SElliott Hughes #define STREAM_HEADER_SIZE 12 26*d2c16535SElliott Hughes 27*d2c16535SElliott Hughes #define HEADER_MAGIC "\3757zXZ" 28*d2c16535SElliott Hughes #define HEADER_MAGIC_SIZE 6 29*d2c16535SElliott Hughes 30*d2c16535SElliott Hughes #define FOOTER_MAGIC "YZ" 31*d2c16535SElliott Hughes #define FOOTER_MAGIC_SIZE 2 32*d2c16535SElliott Hughes 33*d2c16535SElliott Hughes /* 34*d2c16535SElliott Hughes * Variable-length integer can hold a 63-bit unsigned integer or a special 35*d2c16535SElliott Hughes * value indicating that the value is unknown. 36*d2c16535SElliott Hughes * 37*d2c16535SElliott Hughes * Experimental: vli_type can be defined to uint32_t to save a few bytes 38*d2c16535SElliott Hughes * in code size (no effect on speed). Doing so limits the uncompressed and 39*d2c16535SElliott Hughes * compressed size of the file to less than 256 MiB and may also weaken 40*d2c16535SElliott Hughes * error detection slightly. 41*d2c16535SElliott Hughes */ 42*d2c16535SElliott Hughes typedef uint64_t vli_type; 43*d2c16535SElliott Hughes 44*d2c16535SElliott Hughes #define VLI_MAX ((vli_type)-1 / 2) 45*d2c16535SElliott Hughes #define VLI_UNKNOWN ((vli_type)-1) 46*d2c16535SElliott Hughes 47*d2c16535SElliott Hughes /* Maximum encoded size of a VLI */ 48*d2c16535SElliott Hughes #define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7) 49*d2c16535SElliott Hughes 50*d2c16535SElliott Hughes /* Integrity Check types */ 51*d2c16535SElliott Hughes enum xz_check { 52*d2c16535SElliott Hughes XZ_CHECK_NONE = 0, 53*d2c16535SElliott Hughes XZ_CHECK_CRC32 = 1, 54*d2c16535SElliott Hughes XZ_CHECK_CRC64 = 4, 55*d2c16535SElliott Hughes XZ_CHECK_SHA256 = 10 56*d2c16535SElliott Hughes }; 57*d2c16535SElliott Hughes 58*d2c16535SElliott Hughes /* Maximum possible Check ID */ 59*d2c16535SElliott Hughes #define XZ_CHECK_MAX 15 60*d2c16535SElliott Hughes 61*d2c16535SElliott Hughes #endif 62