xz_stream.h 1.4 KB

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