~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/boot/decompressor/xz.c

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
#include <grub/types.h>
 
20
#include <grub/misc.h>
 
21
#include <grub/decompressor.h>
 
22
 
 
23
#include "xz.h"
 
24
#include "xz_stream.h"
 
25
 
 
26
void
 
27
grub_decompress_core (void *src, void *dst, unsigned long srcsize,
 
28
                      unsigned long dstsize)
 
29
{
 
30
  struct xz_dec *dec;
 
31
  struct xz_buf buf;
 
32
 
 
33
  find_scratch (src, dst, srcsize, dstsize);
 
34
 
 
35
  dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE);
 
36
 
 
37
  buf.in = src;
 
38
  buf.in_pos = 0;
 
39
  buf.in_size = srcsize;
 
40
  buf.out = dst;
 
41
  buf.out_pos = 0;
 
42
  buf.out_size = dstsize;
 
43
 
 
44
  while (buf.in_pos != buf.in_size)
 
45
    {
 
46
      enum xz_ret xzret;
 
47
      xzret = xz_dec_run (dec, &buf);
 
48
      switch (xzret)
 
49
        {
 
50
        case XZ_MEMLIMIT_ERROR:
 
51
        case XZ_FORMAT_ERROR:
 
52
        case XZ_OPTIONS_ERROR:
 
53
        case XZ_DATA_ERROR:
 
54
        case XZ_BUF_ERROR:
 
55
          return;
 
56
        default:
 
57
          break;
 
58
        }
 
59
    }
 
60
}