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

« back to all changes in this revision

Viewing changes to grub-core/kern/fs.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
/* fs.c - filesystem manager */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2002,2005,2007  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/disk.h>
 
21
#include <grub/net.h>
 
22
#include <grub/fs.h>
 
23
#include <grub/file.h>
 
24
#include <grub/err.h>
 
25
#include <grub/misc.h>
 
26
#include <grub/types.h>
 
27
#include <grub/mm.h>
 
28
#include <grub/term.h>
 
29
 
 
30
grub_fs_t grub_fs_list = 0;
 
31
 
 
32
grub_fs_autoload_hook_t grub_fs_autoload_hook = 0;
 
33
 
 
34
grub_fs_t
 
35
grub_fs_probe (grub_device_t device)
 
36
{
 
37
  grub_fs_t p;
 
38
  auto int dummy_func (const char *filename,
 
39
                       const struct grub_dirhook_info *info);
 
40
 
 
41
  int dummy_func (const char *filename __attribute__ ((unused)),
 
42
                  const struct grub_dirhook_info *info  __attribute__ ((unused)))
 
43
    {
 
44
      return 1;
 
45
    }
 
46
 
 
47
  if (device->disk)
 
48
    {
 
49
      /* Make it sure not to have an infinite recursive calls.  */
 
50
      static int count = 0;
 
51
 
 
52
      for (p = grub_fs_list; p; p = p->next)
 
53
        {
 
54
          grub_dprintf ("fs", "Detecting %s...\n", p->name);
 
55
          (p->dir) (device, "/", dummy_func);
 
56
          if (grub_errno == GRUB_ERR_NONE)
 
57
            return p;
 
58
 
 
59
          grub_error_push ();
 
60
          grub_dprintf ("fs", "%s detection failed.\n", p->name);
 
61
          grub_error_pop ();
 
62
 
 
63
          if (grub_errno != GRUB_ERR_BAD_FS)
 
64
            return 0;
 
65
 
 
66
          grub_errno = GRUB_ERR_NONE;
 
67
        }
 
68
 
 
69
      /* Let's load modules automatically.  */
 
70
      if (grub_fs_autoload_hook && count == 0)
 
71
        {
 
72
          count++;
 
73
 
 
74
          while (grub_fs_autoload_hook ())
 
75
            {
 
76
              p = grub_fs_list;
 
77
 
 
78
              (p->dir) (device, "/", dummy_func);
 
79
              if (grub_errno == GRUB_ERR_NONE)
 
80
                {
 
81
                  count--;
 
82
                  return p;
 
83
                }
 
84
 
 
85
              if (grub_errno != GRUB_ERR_BAD_FS)
 
86
                {
 
87
                  count--;
 
88
                  return 0;
 
89
                }
 
90
 
 
91
              grub_errno = GRUB_ERR_NONE;
 
92
            }
 
93
 
 
94
          count--;
 
95
        }
 
96
    }
 
97
  else if (device->net->fs)
 
98
    return device->net->fs;
 
99
 
 
100
  grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem");
 
101
  return 0;
 
102
}
 
103
 
 
104
 
 
105
 
 
106
/* Block list support routines.  */
 
107
 
 
108
struct grub_fs_block
 
109
{
 
110
  grub_disk_addr_t offset;
 
111
  unsigned long length;
 
112
};
 
113
 
 
114
static grub_err_t
 
115
grub_fs_blocklist_open (grub_file_t file, const char *name)
 
116
{
 
117
  char *p = (char *) name;
 
118
  unsigned num = 0;
 
119
  unsigned i;
 
120
  grub_disk_t disk = file->device->disk;
 
121
  struct grub_fs_block *blocks;
 
122
 
 
123
  /* First, count the number of blocks.  */
 
124
  do
 
125
    {
 
126
      num++;
 
127
      p = grub_strchr (p, ',');
 
128
      if (p)
 
129
        p++;
 
130
    }
 
131
  while (p);
 
132
 
 
133
  /* Allocate a block list.  */
 
134
  blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1));
 
135
  if (! blocks)
 
136
    return 0;
 
137
 
 
138
  file->size = 0;
 
139
  p = (char *) name;
 
140
  for (i = 0; i < num; i++)
 
141
    {
 
142
      if (*p != '+')
 
143
        {
 
144
          blocks[i].offset = grub_strtoull (p, &p, 0);
 
145
          if (grub_errno != GRUB_ERR_NONE || *p != '+')
 
146
            {
 
147
              grub_error (GRUB_ERR_BAD_FILENAME,
 
148
                          "invalid file name `%s'", name);
 
149
              goto fail;
 
150
            }
 
151
        }
 
152
 
 
153
      p++;
 
154
      blocks[i].length = grub_strtoul (p, &p, 0);
 
155
      if (grub_errno != GRUB_ERR_NONE
 
156
          || blocks[i].length == 0
 
157
          || (*p && *p != ',' && ! grub_isspace (*p)))
 
158
        {
 
159
          grub_error (GRUB_ERR_BAD_FILENAME,
 
160
                      "invalid file name `%s'", name);
 
161
          goto fail;
 
162
        }
 
163
 
 
164
      if (disk->total_sectors < blocks[i].offset + blocks[i].length)
 
165
        {
 
166
          grub_error (GRUB_ERR_BAD_FILENAME, "beyond the total sectors");
 
167
          goto fail;
 
168
        }
 
169
 
 
170
      file->size += (blocks[i].length << GRUB_DISK_SECTOR_BITS);
 
171
      p++;
 
172
    }
 
173
 
 
174
  file->data = blocks;
 
175
 
 
176
  return GRUB_ERR_NONE;
 
177
 
 
178
 fail:
 
179
  grub_free (blocks);
 
180
  return grub_errno;
 
181
}
 
182
 
 
183
static grub_ssize_t
 
184
grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len)
 
185
{
 
186
  struct grub_fs_block *p;
 
187
  grub_disk_addr_t sector;
 
188
  grub_off_t offset;
 
189
  grub_ssize_t ret = 0;
 
190
 
 
191
  if (len > file->size - file->offset)
 
192
    len = file->size - file->offset;
 
193
 
 
194
  sector = (file->offset >> GRUB_DISK_SECTOR_BITS);
 
195
  offset = (file->offset & (GRUB_DISK_SECTOR_SIZE - 1));
 
196
  for (p = file->data; p->length && len > 0; p++)
 
197
    {
 
198
      if (sector < p->length)
 
199
        {
 
200
          grub_size_t size;
 
201
 
 
202
          size = len;
 
203
          if (((size + offset + GRUB_DISK_SECTOR_SIZE - 1)
 
204
               >> GRUB_DISK_SECTOR_BITS) > p->length - sector)
 
205
            size = ((p->length - sector) << GRUB_DISK_SECTOR_BITS) - offset;
 
206
 
 
207
          if (grub_disk_read (file->device->disk, p->offset + sector, offset,
 
208
                              size, buf) != GRUB_ERR_NONE)
 
209
            return -1;
 
210
 
 
211
          ret += size;
 
212
          len -= size;
 
213
          sector -= ((size + offset) >> GRUB_DISK_SECTOR_BITS);
 
214
          offset = ((size + offset) & (GRUB_DISK_SECTOR_SIZE - 1));
 
215
        }
 
216
      else
 
217
        sector -= p->length;
 
218
    }
 
219
 
 
220
  return ret;
 
221
}
 
222
 
 
223
struct grub_fs grub_fs_blocklist =
 
224
  {
 
225
    .name = "blocklist",
 
226
    .dir = 0,
 
227
    .open = grub_fs_blocklist_open,
 
228
    .read = grub_fs_blocklist_read,
 
229
    .close = 0,
 
230
    .next = 0
 
231
  };