~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/io/bufio.c

  • 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
/* bufio.c - buffered io access */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2008  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
#include <grub/err.h>
 
21
#include <grub/types.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/misc.h>
 
24
#include <grub/fs.h>
 
25
#include <grub/bufio.h>
 
26
 
 
27
#define GRUB_BUFIO_DEF_SIZE     8192
 
28
#define GRUB_BUFIO_MAX_SIZE     1048576
 
29
 
 
30
struct grub_bufio
 
31
{
 
32
  grub_file_t file;
 
33
  grub_size_t block_size;
 
34
  grub_size_t buffer_len;
 
35
  char buffer[0];
 
36
};
 
37
typedef struct grub_bufio *grub_bufio_t;
 
38
 
 
39
static struct grub_fs grub_bufio_fs;
 
40
 
 
41
grub_file_t
 
42
grub_bufio_open (grub_file_t io, int size)
 
43
{
 
44
  grub_file_t file;
 
45
  grub_bufio_t bufio = 0;
 
46
 
 
47
  file = (grub_file_t) grub_malloc (sizeof (*file));
 
48
  if (! file)
 
49
    return 0;
 
50
 
 
51
  if (size == 0)
 
52
    size = GRUB_BUFIO_DEF_SIZE;
 
53
  else if (size > GRUB_BUFIO_MAX_SIZE)
 
54
    size = GRUB_BUFIO_MAX_SIZE;
 
55
 
 
56
  if ((size < 0) || ((unsigned) size > io->size))
 
57
    size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
 
58
            io->size);
 
59
 
 
60
  bufio = grub_malloc (sizeof (struct grub_bufio) + size);
 
61
  if (! bufio)
 
62
    {
 
63
      grub_free (file);
 
64
      return 0;
 
65
    }
 
66
 
 
67
  bufio->file = io;
 
68
  bufio->block_size = size;
 
69
  bufio->buffer_len = 0;
 
70
 
 
71
  file->device = io->device;
 
72
  file->offset = 0;
 
73
  file->size = io->size;
 
74
  file->data = bufio;
 
75
  file->read_hook = 0;
 
76
  file->fs = &grub_bufio_fs;
 
77
  file->not_easly_seekable = io->not_easly_seekable;
 
78
 
 
79
  return file;
 
80
}
 
81
 
 
82
grub_file_t
 
83
grub_buffile_open (const char *name, int size)
 
84
{
 
85
  grub_file_t io, file;
 
86
 
 
87
  io = grub_file_open (name);
 
88
  if (! io)
 
89
    return 0;
 
90
 
 
91
  file = grub_bufio_open (io, size);
 
92
  if (! file)
 
93
    {
 
94
      grub_file_close (io);
 
95
      return 0;
 
96
    }
 
97
 
 
98
  return file;
 
99
}
 
100
 
 
101
static grub_ssize_t
 
102
grub_bufio_read (grub_file_t file, char *buf, grub_size_t len)
 
103
{
 
104
  grub_size_t res = len;
 
105
  grub_bufio_t bufio = file->data;
 
106
  grub_uint32_t pos;
 
107
 
 
108
  if ((file->offset >= bufio->file->offset) &&
 
109
      (file->offset < bufio->file->offset + bufio->buffer_len))
 
110
    {
 
111
      grub_size_t n;
 
112
 
 
113
      pos = file->offset - bufio->file->offset;
 
114
      n = bufio->buffer_len - pos;
 
115
      if (n > len)
 
116
        n = len;
 
117
 
 
118
      grub_memcpy (buf, &bufio->buffer[pos], n);
 
119
      len -= n;
 
120
      if (! len)
 
121
        return res;
 
122
 
 
123
      buf += n;
 
124
      bufio->file->offset += bufio->buffer_len;
 
125
      pos = 0;
 
126
    }
 
127
  else
 
128
    {
 
129
      bufio->file->offset = grub_divmod64 (file->offset, bufio->block_size,
 
130
                                           &pos);
 
131
      bufio->file->offset *= bufio->block_size;
 
132
    }
 
133
 
 
134
  if (pos + len >= bufio->block_size)
 
135
    {
 
136
      if (pos)
 
137
        {
 
138
          grub_size_t n;
 
139
 
 
140
          bufio->file->fs->read (bufio->file, bufio->buffer,
 
141
                                 bufio->block_size);
 
142
          if (grub_errno)
 
143
            return -1;
 
144
 
 
145
          n = bufio->block_size - pos;
 
146
          grub_memcpy (buf, &bufio->buffer[pos], n);
 
147
          len -= n;
 
148
          buf += n;
 
149
          bufio->file->offset += bufio->block_size;
 
150
          pos = 0;
 
151
        }
 
152
 
 
153
      while (len >= bufio->block_size)
 
154
        {
 
155
          bufio->file->fs->read (bufio->file, buf, bufio->block_size);
 
156
          if (grub_errno)
 
157
            return -1;
 
158
 
 
159
          len -= bufio->block_size;
 
160
          buf += bufio->block_size;
 
161
          bufio->file->offset += bufio->block_size;
 
162
        }
 
163
 
 
164
      if (! len)
 
165
        {
 
166
          bufio->buffer_len = 0;
 
167
          return res;
 
168
        }
 
169
    }
 
170
 
 
171
  bufio->buffer_len = bufio->file->size - bufio->file->offset;
 
172
  if (bufio->buffer_len > bufio->block_size)
 
173
    bufio->buffer_len = bufio->block_size;
 
174
 
 
175
  bufio->file->fs->read (bufio->file, bufio->buffer, bufio->buffer_len);
 
176
  if (grub_errno)
 
177
    return -1;
 
178
 
 
179
  grub_memcpy (buf, &bufio->buffer[pos], len);
 
180
 
 
181
  return res;
 
182
}
 
183
 
 
184
static grub_err_t
 
185
grub_bufio_close (grub_file_t file)
 
186
{
 
187
  grub_bufio_t bufio = file->data;
 
188
 
 
189
  grub_file_close (bufio->file);
 
190
  grub_free (bufio);
 
191
 
 
192
  file->device = 0;
 
193
 
 
194
  return grub_errno;
 
195
}
 
196
 
 
197
static struct grub_fs grub_bufio_fs =
 
198
  {
 
199
    .name = "bufio",
 
200
    .dir = 0,
 
201
    .open = 0,
 
202
    .read = grub_bufio_read,
 
203
    .close = grub_bufio_close,
 
204
    .label = 0,
 
205
    .next = 0
 
206
  };