xz_private.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* xz_private.h - Private includes and definitions */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2010 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * This file is based on code from XZ embedded project
  21. * http://tukaani.org/xz/embedded.html
  22. */
  23. #ifndef XZ_PRIVATE_H
  24. #define XZ_PRIVATE_H
  25. /*
  26. * For userspace builds, use a separate header to define the required
  27. * macros and functions. This makes it easier to adapt the code into
  28. * different environments and avoids clutter in the Linux kernel tree.
  29. */
  30. #include "xz_config.h"
  31. /*
  32. * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
  33. * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
  34. */
  35. #ifndef XZ_DEC_BCJ
  36. # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
  37. || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
  38. || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
  39. || defined(XZ_DEC_SPARC)
  40. # define XZ_DEC_BCJ
  41. # endif
  42. #endif
  43. /*
  44. * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
  45. * before calling xz_dec_lzma2_run().
  46. */
  47. struct xz_dec_lzma2 * xz_dec_lzma2_create(
  48. uint32_t dict_max);
  49. /*
  50. * Decode the LZMA2 properties (one byte) and reset the decoder. Return
  51. * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
  52. * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
  53. * decoder doesn't support.
  54. */
  55. enum xz_ret xz_dec_lzma2_reset(
  56. struct xz_dec_lzma2 *s, uint8_t props);
  57. /* Decode raw LZMA2 stream from b->in to b->out. */
  58. enum xz_ret xz_dec_lzma2_run(
  59. struct xz_dec_lzma2 *s, struct xz_buf *b);
  60. /* Free the memory allocated for the LZMA2 decoder. */
  61. void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
  62. /*
  63. * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
  64. * calling xz_dec_bcj_run().
  65. */
  66. struct xz_dec_bcj * xz_dec_bcj_create(bool single_call);
  67. /*
  68. * Decode the Filter ID of a BCJ filter. This implementation doesn't
  69. * support custom start offsets, so no decoding of Filter Properties
  70. * is needed. Returns XZ_OK if the given Filter ID is supported.
  71. * Otherwise XZ_OPTIONS_ERROR is returned.
  72. */
  73. enum xz_ret xz_dec_bcj_reset(
  74. struct xz_dec_bcj *s, uint8_t id);
  75. /*
  76. * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
  77. * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
  78. * must be called directly.
  79. */
  80. enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
  81. struct xz_dec_lzma2 *lzma2, struct xz_buf *b);
  82. /* Free the memory allocated for the BCJ filters. */
  83. #define xz_dec_bcj_end(s) kfree(s)
  84. #endif