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

« back to all changes in this revision

Viewing changes to 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
 
 
78
 
  return file;
79
 
}
80
 
 
81
 
grub_file_t
82
 
grub_buffile_open (const char *name, int size)
83
 
{
84
 
  grub_file_t io, file;
85
 
 
86
 
  io = grub_file_open (name);
87
 
  if (! io)
88
 
    return 0;
89
 
 
90
 
  file = grub_bufio_open (io, size);
91
 
  if (! file)
92
 
    {
93
 
      grub_file_close (io);
94
 
      return 0;
95
 
    }
96
 
 
97
 
  return file;
98
 
}
99
 
 
100
 
static grub_ssize_t
101
 
grub_bufio_read (grub_file_t file, char *buf, grub_size_t len)
102
 
{
103
 
  grub_size_t res = len;
104
 
  grub_bufio_t bufio = file->data;
105
 
  grub_uint32_t pos;
106
 
 
107
 
  if ((file->offset >= bufio->file->offset) &&
108
 
      (file->offset < bufio->file->offset + bufio->buffer_len))
109
 
    {
110
 
      grub_size_t n;
111
 
 
112
 
      pos = file->offset - bufio->file->offset;
113
 
      n = bufio->buffer_len - pos;
114
 
      if (n > len)
115
 
        n = len;
116
 
 
117
 
      grub_memcpy (buf, &bufio->buffer[pos], n);
118
 
      len -= n;
119
 
      if (! len)
120
 
        return res;
121
 
 
122
 
      buf += n;
123
 
      bufio->file->offset += bufio->buffer_len;
124
 
      pos = 0;
125
 
    }
126
 
  else
127
 
    {
128
 
      bufio->file->offset = grub_divmod64 (file->offset, bufio->block_size,
129
 
                                           &pos);
130
 
      bufio->file->offset *= bufio->block_size;
131
 
    }
132
 
 
133
 
  if (pos + len >= bufio->block_size)
134
 
    {
135
 
      if (pos)
136
 
        {
137
 
          grub_size_t n;
138
 
 
139
 
          bufio->file->fs->read (bufio->file, bufio->buffer,
140
 
                                 bufio->block_size);
141
 
          if (grub_errno)
142
 
            return -1;
143
 
 
144
 
          n = bufio->block_size - pos;
145
 
          grub_memcpy (buf, &bufio->buffer[pos], n);
146
 
          len -= n;
147
 
          buf += n;
148
 
          bufio->file->offset += bufio->block_size;
149
 
          pos = 0;
150
 
        }
151
 
 
152
 
      while (len >= bufio->block_size)
153
 
        {
154
 
          bufio->file->fs->read (bufio->file, buf, bufio->block_size);
155
 
          if (grub_errno)
156
 
            return -1;
157
 
 
158
 
          len -= bufio->block_size;
159
 
          buf += bufio->block_size;
160
 
          bufio->file->offset += bufio->block_size;
161
 
        }
162
 
 
163
 
      if (! len)
164
 
        {
165
 
          bufio->buffer_len = 0;
166
 
          return res;
167
 
        }
168
 
    }
169
 
 
170
 
  bufio->buffer_len = bufio->file->size - bufio->file->offset;
171
 
  if (bufio->buffer_len > bufio->block_size)
172
 
    bufio->buffer_len = bufio->block_size;
173
 
 
174
 
  bufio->file->fs->read (bufio->file, bufio->buffer, bufio->buffer_len);
175
 
  if (grub_errno)
176
 
    return -1;
177
 
 
178
 
  grub_memcpy (buf, &bufio->buffer[pos], len);
179
 
 
180
 
  return res;
181
 
}
182
 
 
183
 
static grub_err_t
184
 
grub_bufio_close (grub_file_t file)
185
 
{
186
 
  grub_bufio_t bufio = file->data;
187
 
 
188
 
  grub_file_close (bufio->file);
189
 
  grub_free (bufio);
190
 
 
191
 
  file->device = 0;
192
 
 
193
 
  return grub_errno;
194
 
}
195
 
 
196
 
static struct grub_fs grub_bufio_fs =
197
 
  {
198
 
    .name = "bufio",
199
 
    .dir = 0,
200
 
    .open = 0,
201
 
    .read = grub_bufio_read,
202
 
    .close = grub_bufio_close,
203
 
    .label = 0,
204
 
    .next = 0
205
 
  };