~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/lib/xzembed/xz.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* xz.h - XZ decompressor */
 
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
 
 
24
#ifndef XZ_H
 
25
#define XZ_H
 
26
 
 
27
#include <stdint.h>
 
28
 
 
29
/**
 
30
 * enum xz_ret - Return codes
 
31
 * @XZ_OK:              Everything is OK so far. More input or more output
 
32
 *                      space is required to continue.
 
33
 * @XZ_STREAM_END:      Operation finished successfully.
 
34
 * @XZ_MEMLIMIT_ERROR:  Not enough memory was preallocated at decoder
 
35
 *                      initialization time.
 
36
 * @XZ_FORMAT_ERROR:    File format was not recognized (wrong magic bytes).
 
37
 * @XZ_OPTIONS_ERROR:   This implementation doesn't support the requested
 
38
 *                      compression options. In the decoder this means that
 
39
 *                      the header CRC32 matches, but the header itself
 
40
 *                      specifies something that we don't support.
 
41
 * @XZ_DATA_ERROR:      Compressed data is corrupt.
 
42
 * @XZ_BUF_ERROR:       Cannot make any progress. Details are slightly
 
43
 *                      different between multi-call and single-call mode;
 
44
 *                      more information below.
 
45
 *
 
46
 * In multi-call mode, XZ_BUF_ERROR is returned when two consecutive calls
 
47
 * to XZ code cannot consume any input and cannot produce any new output.
 
48
 * This happens when there is no new input available, or the output buffer
 
49
 * is full while at least one output byte is still pending. Assuming your
 
50
 * code is not buggy, you can get this error only when decoding a compressed
 
51
 * stream that is truncated or otherwise corrupt.
 
52
 *
 
53
 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
 
54
 * is too small, or the compressed input is corrupt in a way that makes the
 
55
 * decoder produce more output than the caller expected. When it is
 
56
 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
 
57
 * is used instead of XZ_BUF_ERROR.
 
58
 */
 
59
enum xz_ret {
 
60
        XZ_OK,
 
61
        XZ_STREAM_END,
 
62
        XZ_MEMLIMIT_ERROR,
 
63
        XZ_FORMAT_ERROR,
 
64
        XZ_OPTIONS_ERROR,
 
65
        XZ_DATA_ERROR,
 
66
        XZ_BUF_ERROR
 
67
};
 
68
 
 
69
/**
 
70
 * struct xz_buf - Passing input and output buffers to XZ code
 
71
 * @in:         Beginning of the input buffer. This may be NULL if and only
 
72
 *              if in_pos is equal to in_size.
 
73
 * @in_pos:     Current position in the input buffer. This must not exceed
 
74
 *              in_size.
 
75
 * @in_size:    Size of the input buffer
 
76
 * @out:        Beginning of the output buffer. This may be NULL if and only
 
77
 *              if out_pos is equal to out_size.
 
78
 * @out_pos:    Current position in the output buffer. This must not exceed
 
79
 *              out_size.
 
80
 * @out_size:   Size of the output buffer
 
81
 *
 
82
 * Only the contents of the output buffer from out[out_pos] onward, and
 
83
 * the variables in_pos and out_pos are modified by the XZ code.
 
84
 */
 
85
struct xz_buf {
 
86
        const uint8_t *in;
 
87
        size_t in_pos;
 
88
        size_t in_size;
 
89
 
 
90
        uint8_t *out;
 
91
        size_t out_pos;
 
92
        size_t out_size;
 
93
};
 
94
 
 
95
/**
 
96
 * struct xz_dec - Opaque type to hold the XZ decoder state
 
97
 */
 
98
struct xz_dec;
 
99
 
 
100
/**
 
101
 * xz_dec_init() - Allocate and initialize a XZ decoder state
 
102
 * @dict_max:   Maximum size of the LZMA2 dictionary (history buffer) for
 
103
 *              multi-call decoding, or special value of zero to indicate
 
104
 *              single-call decoding mode.
 
105
 *
 
106
 * If dict_max > 0, the decoder is initialized to work in multi-call mode.
 
107
 * dict_max number of bytes of memory is preallocated for the LZMA2
 
108
 * dictionary. This way there is no risk that xz_dec_run() could run out
 
109
 * of memory, since xz_dec_run() will never allocate any memory. Instead,
 
110
 * if the preallocated dictionary is too small for decoding the given input
 
111
 * stream, xz_dec_run() will return XZ_MEMLIMIT_ERROR. Thus, it is important
 
112
 * to know what kind of data will be decoded to avoid allocating excessive
 
113
 * amount of memory for the dictionary.
 
114
 *
 
115
 * LZMA2 dictionary is always 2^n bytes or 2^n + 2^(n-1) bytes (the latter
 
116
 * sizes are less common in practice). In the kernel, dictionary sizes of
 
117
 * 64 KiB, 128 KiB, 256 KiB, 512 KiB, and 1 MiB are probably the only
 
118
 * reasonable values.
 
119
 *
 
120
 * If dict_max == 0, the decoder is initialized to work in single-call mode.
 
121
 * In single-call mode, xz_dec_run() decodes the whole stream at once. The
 
122
 * caller must provide enough output space or the decoding will fail. The
 
123
 * output space is used as the dictionary buffer, which is why there is
 
124
 * no need to allocate the dictionary as part of the decoder's internal
 
125
 * state.
 
126
 *
 
127
 * Because the output buffer is used as the workspace, streams encoded using
 
128
 * a big dictionary are not a problem in single-call. It is enough that the
 
129
 * output buffer is is big enough to hold the actual uncompressed data; it
 
130
 * can be smaller than the dictionary size stored in the stream headers.
 
131
 *
 
132
 * On success, xz_dec_init() returns a pointer to struct xz_dec, which is
 
133
 * ready to be used with xz_dec_run(). On error, xz_dec_init() returns NULL.
 
134
 */
 
135
struct xz_dec * xz_dec_init(uint32_t dict_max);
 
136
 
 
137
/**
 
138
 * xz_dec_run() - Run the XZ decoder
 
139
 * @s:          Decoder state allocated using xz_dec_init()
 
140
 * @b:          Input and output buffers
 
141
 *
 
142
 * In multi-call mode, this function may return any of the values listed in
 
143
 * enum xz_ret.
 
144
 *
 
145
 * In single-call mode, this function never returns XZ_OK. If an error occurs
 
146
 * in single-call mode (return value is not XZ_STREAM_END), b->in_pos and
 
147
 * b->out_pos are not modified, and the contents of the output buffer from
 
148
 * b->out[b->out_pos] onward are undefined.
 
149
 *
 
150
 * NOTE: In single-call mode, the contents of the output buffer are undefined
 
151
 * also after XZ_BUF_ERROR. This is because with some filter chains, there
 
152
 * may be a second pass over the output buffer, and this pass cannot be
 
153
 * properly done if the output buffer is truncated. Thus, you cannot give
 
154
 * the single-call decoder a too small buffer and then expect to get that
 
155
 * amount valid data from the beginning of the stream. You must use the
 
156
 * multi-call decoder if you don't want to uncompress the whole stream.
 
157
 */
 
158
enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b);
 
159
 
 
160
/**
 
161
 * xz_dec_reset() - Reset an already allocated decoder state
 
162
 * @s:          Decoder state allocated using xz_dec_init()
 
163
 *
 
164
 * This function can be used to reset the multi-call decoder state without
 
165
 * freeing and reallocating memory with xz_dec_end() and xz_dec_init().
 
166
 *
 
167
 * In single-call mode, xz_dec_reset() is always called in the beginning of
 
168
 * xz_dec_run(). Thus, explicit call to xz_dec_reset() is useful only in
 
169
 * multi-call mode.
 
170
 */
 
171
void xz_dec_reset(struct xz_dec *s);
 
172
 
 
173
/**
 
174
 * xz_dec_end() - Free the memory allocated for the decoder state
 
175
 * @s:          Decoder state allocated using xz_dec_init(). If s is NULL,
 
176
 *              this function does nothing.
 
177
 */
 
178
void xz_dec_end(struct xz_dec *s);
 
179
 
 
180
#endif