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

« back to all changes in this revision

Viewing changes to grub-core/kern/device.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* device.c - device manager */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2002,2005,2007,2008,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/device.h>
 
21
#include <grub/disk.h>
 
22
#include <grub/net.h>
 
23
#include <grub/fs.h>
 
24
#include <grub/mm.h>
 
25
#include <grub/misc.h>
 
26
#include <grub/env.h>
 
27
#include <grub/partition.h>
 
28
 
 
29
grub_device_t
 
30
grub_device_open (const char *name)
 
31
{
 
32
  grub_disk_t disk = 0;
 
33
  grub_device_t dev = 0;
 
34
 
 
35
  if (! name)
 
36
    {
 
37
      name = grub_env_get ("root");
 
38
      if (*name == '\0')
 
39
        {
 
40
          grub_error (GRUB_ERR_BAD_DEVICE, "no device is set");
 
41
          goto fail;
 
42
        }
 
43
    }
 
44
 
 
45
  dev = grub_malloc (sizeof (*dev));
 
46
  if (! dev)
 
47
    goto fail;
 
48
 
 
49
  /* Try to open a disk.  */
 
50
  disk = grub_disk_open (name);
 
51
  if (! disk)
 
52
    goto fail;
 
53
 
 
54
  dev->disk = disk;
 
55
  dev->net = 0; /* FIXME */
 
56
 
 
57
  return dev;
 
58
 
 
59
 fail:
 
60
  if (disk)
 
61
    grub_disk_close (disk);
 
62
 
 
63
  grub_free (dev);
 
64
 
 
65
  return 0;
 
66
}
 
67
 
 
68
grub_err_t
 
69
grub_device_close (grub_device_t device)
 
70
{
 
71
  if (device->disk)
 
72
    grub_disk_close (device->disk);
 
73
 
 
74
  grub_free (device);
 
75
 
 
76
  return grub_errno;
 
77
}
 
78
 
 
79
int
 
80
grub_device_iterate (int (*hook) (const char *name))
 
81
{
 
82
  auto int iterate_disk (const char *disk_name);
 
83
  auto int iterate_partition (grub_disk_t disk,
 
84
                              const grub_partition_t partition);
 
85
 
 
86
  struct part_ent
 
87
  {
 
88
    struct part_ent *next;
 
89
    char *name;
 
90
  } *ents;
 
91
 
 
92
  int iterate_disk (const char *disk_name)
 
93
    {
 
94
      grub_device_t dev;
 
95
 
 
96
      if (hook (disk_name))
 
97
        return 1;
 
98
 
 
99
      dev = grub_device_open (disk_name);
 
100
      if (! dev)
 
101
        {
 
102
          grub_errno = GRUB_ERR_NONE;
 
103
          return 0;
 
104
        }
 
105
 
 
106
      if (dev->disk)
 
107
        {
 
108
          struct part_ent *p;
 
109
          int ret = 0;
 
110
 
 
111
          ents = NULL;
 
112
          (void) grub_partition_iterate (dev->disk, iterate_partition);
 
113
          grub_device_close (dev);
 
114
 
 
115
          grub_errno = GRUB_ERR_NONE;
 
116
 
 
117
          p = ents;
 
118
          while (p != NULL)
 
119
            {
 
120
              struct part_ent *next = p->next;
 
121
 
 
122
              if (!ret)
 
123
                ret = hook (p->name);
 
124
              grub_free (p->name);
 
125
              grub_free (p);
 
126
              p = next;
 
127
            }
 
128
 
 
129
          return ret;
 
130
        }
 
131
 
 
132
      grub_device_close (dev);
 
133
      return 0;
 
134
    }
 
135
 
 
136
  int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
 
137
    {
 
138
      struct part_ent *p;
 
139
      char *part_name;
 
140
 
 
141
      p = grub_malloc (sizeof (*p));
 
142
      if (!p)
 
143
        {
 
144
          return 1;
 
145
        }
 
146
 
 
147
      part_name = grub_partition_get_name (partition);
 
148
      if (!part_name)
 
149
        {
 
150
          grub_free (p);
 
151
          return 1;
 
152
        }
 
153
      p->name = grub_xasprintf ("%s,%s", disk->name, part_name);
 
154
      grub_free (part_name);
 
155
      if (!p->name)
 
156
        {
 
157
          grub_free (p);
 
158
          return 1;
 
159
        }
 
160
 
 
161
      p->next = ents;
 
162
      ents = p;
 
163
 
 
164
      return 0;
 
165
    }
 
166
 
 
167
  /* Only disk devices are supported at the moment.  */
 
168
  return grub_disk_dev_iterate (iterate_disk);
 
169
}