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

« back to all changes in this revision

Viewing changes to kern/file.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
 
/* file.c - file I/O functions */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2002,2006,2007,2009  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/misc.h>
21
 
#include <grub/err.h>
22
 
#include <grub/file.h>
23
 
#include <grub/mm.h>
24
 
#include <grub/fs.h>
25
 
#include <grub/device.h>
26
 
 
27
 
/* Get the device part of the filename NAME. It is enclosed by parentheses.  */
28
 
char *
29
 
grub_file_get_device_name (const char *name)
30
 
{
31
 
  if (name[0] == '(')
32
 
    {
33
 
      char *p = grub_strchr (name, ')');
34
 
      char *ret;
35
 
 
36
 
      if (! p)
37
 
        {
38
 
          grub_error (GRUB_ERR_BAD_FILENAME, "missing `)'");
39
 
          return 0;
40
 
        }
41
 
 
42
 
      ret = (char *) grub_malloc (p - name);
43
 
      if (! ret)
44
 
        return 0;
45
 
 
46
 
      grub_memcpy (ret, name + 1, p - name - 1);
47
 
      ret[p - name - 1] = '\0';
48
 
      return ret;
49
 
    }
50
 
 
51
 
  return 0;
52
 
}
53
 
 
54
 
grub_file_t
55
 
grub_file_open (const char *name)
56
 
{
57
 
  grub_device_t device;
58
 
  grub_file_t file = 0;
59
 
  char *device_name;
60
 
  char *file_name;
61
 
 
62
 
  device_name = grub_file_get_device_name (name);
63
 
  if (grub_errno)
64
 
    return 0;
65
 
 
66
 
  /* Get the file part of NAME.  */
67
 
  file_name = grub_strchr (name, ')');
68
 
  if (file_name)
69
 
    file_name++;
70
 
  else
71
 
    file_name = (char *) name;
72
 
 
73
 
  device = grub_device_open (device_name);
74
 
  grub_free (device_name);
75
 
  if (! device)
76
 
    goto fail;
77
 
 
78
 
  file = (grub_file_t) grub_zalloc (sizeof (*file));
79
 
  if (! file)
80
 
    goto fail;
81
 
 
82
 
  file->device = device;
83
 
 
84
 
  if (device->disk && file_name[0] != '/')
85
 
    /* This is a block list.  */
86
 
    file->fs = &grub_fs_blocklist;
87
 
  else
88
 
    {
89
 
      file->fs = grub_fs_probe (device);
90
 
      if (! file->fs)
91
 
        goto fail;
92
 
    }
93
 
 
94
 
  if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
95
 
    goto fail;
96
 
 
97
 
  return file;
98
 
 
99
 
 fail:
100
 
  if (device)
101
 
    grub_device_close (device);
102
 
 
103
 
  /* if (net) grub_net_close (net);  */
104
 
 
105
 
  grub_free (file);
106
 
 
107
 
  return 0;
108
 
}
109
 
 
110
 
grub_ssize_t
111
 
grub_file_read (grub_file_t file, void *buf, grub_size_t len)
112
 
{
113
 
  grub_ssize_t res;
114
 
 
115
 
  if (file->offset > file->size)
116
 
    {
117
 
      grub_error (GRUB_ERR_OUT_OF_RANGE,
118
 
                  "attempt to read past the end of file");
119
 
      return -1;
120
 
    }
121
 
 
122
 
  if (len == 0 || len > file->size - file->offset)
123
 
    len = file->size - file->offset;
124
 
 
125
 
  /* Prevent an overflow.  */
126
 
  if ((grub_ssize_t) len < 0)
127
 
    len >>= 1;
128
 
 
129
 
  if (len == 0)
130
 
    return 0;
131
 
 
132
 
  res = (file->fs->read) (file, buf, len);
133
 
  if (res > 0)
134
 
    file->offset += res;
135
 
 
136
 
  return res;
137
 
}
138
 
 
139
 
grub_err_t
140
 
grub_file_close (grub_file_t file)
141
 
{
142
 
  if (file->fs->close)
143
 
    (file->fs->close) (file);
144
 
 
145
 
  if (file->device)
146
 
    grub_device_close (file->device);
147
 
  grub_free (file);
148
 
  return grub_errno;
149
 
}
150
 
 
151
 
grub_off_t
152
 
grub_file_seek (grub_file_t file, grub_off_t offset)
153
 
{
154
 
  grub_off_t old;
155
 
 
156
 
  if (offset > file->size)
157
 
    {
158
 
      grub_error (GRUB_ERR_OUT_OF_RANGE,
159
 
                  "attempt to seek outside of the file");
160
 
      return -1;
161
 
    }
162
 
 
163
 
  old = file->offset;
164
 
  file->offset = offset;
165
 
  return old;
166
 
}