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

« back to all changes in this revision

Viewing changes to util/grub-emu.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
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <stdlib.h>
20
 
#include <sys/stat.h>
21
 
#include <getopt.h>
22
 
#include <string.h>
23
 
#include <signal.h>
24
 
#include <sys/types.h>
25
 
#include <unistd.h>
26
 
 
27
 
#include <grub/mm.h>
28
 
#include <grub/setjmp.h>
29
 
#include <grub/fs.h>
30
 
#include <grub/util/hostdisk.h>
31
 
#include <grub/dl.h>
32
 
#include <grub/util/console.h>
33
 
#include <grub/util/misc.h>
34
 
#include <grub/kernel.h>
35
 
#include <grub/normal.h>
36
 
#include <grub/util/getroot.h>
37
 
#include <grub/env.h>
38
 
#include <grub/partition.h>
39
 
#include <grub/i18n.h>
40
 
 
41
 
#include <grub_emu_init.h>
42
 
 
43
 
#include "progname.h"
44
 
 
45
 
/* Used for going back to the main function.  */
46
 
static jmp_buf main_env;
47
 
 
48
 
/* Store the prefix specified by an argument.  */
49
 
static char *prefix = NULL;
50
 
 
51
 
grub_addr_t
52
 
grub_arch_modules_addr (void)
53
 
{
54
 
  return NULL;
55
 
}
56
 
 
57
 
grub_err_t
58
 
grub_arch_dl_check_header (void *ehdr)
59
 
{
60
 
  (void) ehdr;
61
 
 
62
 
  return GRUB_ERR_BAD_MODULE;
63
 
}
64
 
 
65
 
grub_err_t
66
 
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
67
 
{
68
 
  (void) mod;
69
 
  (void) ehdr;
70
 
 
71
 
  return GRUB_ERR_BAD_MODULE;
72
 
}
73
 
 
74
 
void
75
 
grub_reboot (void)
76
 
{
77
 
  longjmp (main_env, 1);
78
 
}
79
 
 
80
 
void
81
 
grub_halt (
82
 
#ifdef GRUB_MACHINE_PCBIOS
83
 
           int no_apm __attribute__ ((unused))
84
 
#endif
85
 
           )
86
 
{
87
 
  grub_reboot ();
88
 
}
89
 
 
90
 
void
91
 
grub_machine_init (void)
92
 
{
93
 
}
94
 
 
95
 
void
96
 
grub_machine_set_prefix (void)
97
 
{
98
 
  grub_env_set ("prefix", prefix);
99
 
  free (prefix);
100
 
  prefix = 0;
101
 
}
102
 
 
103
 
void
104
 
grub_machine_fini (void)
105
 
{
106
 
  grub_console_fini ();
107
 
}
108
 
 
109
 
void
110
 
read_command_list (void)
111
 
{
112
 
}
113
 
 
114
 
 
115
 
static struct option options[] =
116
 
  {
117
 
    {"root-device", required_argument, 0, 'r'},
118
 
    {"device-map", required_argument, 0, 'm'},
119
 
    {"directory", required_argument, 0, 'd'},
120
 
    {"hold", optional_argument, 0, 'H'},
121
 
    {"help", no_argument, 0, 'h'},
122
 
    {"version", no_argument, 0, 'V'},
123
 
    {"verbose", no_argument, 0, 'v'},
124
 
    { 0, 0, 0, 0 }
125
 
  };
126
 
 
127
 
static int
128
 
usage (int status)
129
 
{
130
 
  if (status)
131
 
    fprintf (stderr,
132
 
             "Try `%s --help' for more information.\n", program_name);
133
 
  else
134
 
    printf (
135
 
      "Usage: %s [OPTION]...\n"
136
 
      "\n"
137
 
      "GRUB emulator.\n"
138
 
      "\n"
139
 
      "  -r, --root-device=DEV     use DEV as the root device [default=guessed]\n"
140
 
      "  -m, --device-map=FILE     use FILE as the device map [default=%s]\n"
141
 
      "  -d, --directory=DIR       use GRUB files in the directory DIR [default=%s]\n"
142
 
      "  -v, --verbose             print verbose messages\n"
143
 
      "  -H, --hold[=SECONDS]      wait until a debugger will attach\n"
144
 
      "  -h, --help                display this message and exit\n"
145
 
      "  -V, --version             print version information and exit\n"
146
 
      "\n"
147
 
      "Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
148
 
  return status;
149
 
}
150
 
 
151
 
 
152
 
int
153
 
main (int argc, char *argv[])
154
 
{
155
 
  char *root_dev = 0;
156
 
  char *dir = DEFAULT_DIRECTORY;
157
 
  char *dev_map = DEFAULT_DEVICE_MAP;
158
 
  volatile int hold = 0;
159
 
  int opt;
160
 
 
161
 
  set_program_name (argv[0]);
162
 
 
163
 
  grub_util_init_nls ();
164
 
 
165
 
  while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
166
 
    switch (opt)
167
 
      {
168
 
      case 'r':
169
 
        root_dev = optarg;
170
 
        break;
171
 
      case 'd':
172
 
        dir = optarg;
173
 
        break;
174
 
      case 'm':
175
 
        dev_map = optarg;
176
 
        break;
177
 
      case 'v':
178
 
        verbosity++;
179
 
        break;
180
 
      case 'H':
181
 
        hold = (optarg ? atoi (optarg) : -1);
182
 
        break;
183
 
      case 'h':
184
 
        return usage (0);
185
 
      case 'V':
186
 
        printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
187
 
        return 0;
188
 
      default:
189
 
        return usage (1);
190
 
      }
191
 
 
192
 
  if (optind < argc)
193
 
    {
194
 
      fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind]);
195
 
      return usage (1);
196
 
    }
197
 
 
198
 
  /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
199
 
  if (hold && verbosity > 0)
200
 
    printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
201
 
            program_name, (int) getpid ());
202
 
  while (hold)
203
 
    {
204
 
      if (hold > 0)
205
 
        hold--;
206
 
 
207
 
      sleep (1);
208
 
    }
209
 
 
210
 
  signal (SIGINT, SIG_IGN);
211
 
  grub_console_init ();
212
 
 
213
 
  /* XXX: This is a bit unportable.  */
214
 
  grub_util_biosdisk_init (dev_map);
215
 
 
216
 
  grub_init_all ();
217
 
 
218
 
  /* Make sure that there is a root device.  */
219
 
  if (! root_dev)
220
 
    {
221
 
      char *device_name = grub_guess_root_device (dir);
222
 
      if (! device_name)
223
 
        grub_util_error ("cannot find a device for %s", dir);
224
 
 
225
 
      root_dev = grub_util_get_grub_dev (device_name);
226
 
      if (! root_dev)
227
 
        {
228
 
          grub_util_info ("guessing the root device failed, because of `%s'",
229
 
                          grub_errmsg);
230
 
          grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
231
 
        }
232
 
    }
233
 
 
234
 
  dir = grub_get_prefix (dir);
235
 
  prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
236
 
  sprintf (prefix, "(%s)%s", root_dev, dir);
237
 
  free (dir);
238
 
 
239
 
  /* Start GRUB!  */
240
 
  if (setjmp (main_env) == 0)
241
 
    grub_main ();
242
 
 
243
 
  grub_fini_all ();
244
 
 
245
 
  grub_machine_fini ();
246
 
 
247
 
  return 0;
248
 
}