xz.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/types.h>
  19. #include <grub/misc.h>
  20. #include <grub/decompressor.h>
  21. #include "xz.h"
  22. #include "xz_stream.h"
  23. void
  24. grub_decompress_core (void *src, void *dst, unsigned long srcsize,
  25. unsigned long dstsize)
  26. {
  27. struct xz_dec *dec;
  28. struct xz_buf buf;
  29. find_scratch (src, dst, srcsize, dstsize);
  30. dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE);
  31. buf.in = src;
  32. buf.in_pos = 0;
  33. buf.in_size = srcsize;
  34. buf.out = dst;
  35. buf.out_pos = 0;
  36. buf.out_size = dstsize;
  37. while (buf.in_pos != buf.in_size)
  38. {
  39. enum xz_ret xzret;
  40. xzret = xz_dec_run (dec, &buf);
  41. switch (xzret)
  42. {
  43. case XZ_MEMLIMIT_ERROR:
  44. case XZ_FORMAT_ERROR:
  45. case XZ_OPTIONS_ERROR:
  46. case XZ_DATA_ERROR:
  47. case XZ_BUF_ERROR:
  48. return;
  49. default:
  50. break;
  51. }
  52. }
  53. }