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

« back to all changes in this revision

Viewing changes to grub-core/commands/minicmd.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
/* minicmd.c - commands for the rescue mode */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2003,2005,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/dl.h>
 
21
#include <grub/mm.h>
 
22
#include <grub/err.h>
 
23
#include <grub/env.h>
 
24
#include <grub/misc.h>
 
25
#include <grub/file.h>
 
26
#include <grub/disk.h>
 
27
#include <grub/term.h>
 
28
#include <grub/loader.h>
 
29
#include <grub/command.h>
 
30
#include <grub/i18n.h>
 
31
 
 
32
/* cat FILE */
 
33
static grub_err_t
 
34
grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
 
35
                   int argc, char *argv[])
 
36
{
 
37
  grub_file_t file;
 
38
  char buf[GRUB_DISK_SECTOR_SIZE];
 
39
  grub_ssize_t size;
 
40
 
 
41
  if (argc < 1)
 
42
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
 
43
 
 
44
  file = grub_file_open (argv[0]);
 
45
  if (! file)
 
46
    return grub_errno;
 
47
 
 
48
  while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
 
49
    {
 
50
      int i;
 
51
 
 
52
      for (i = 0; i < size; i++)
 
53
        {
 
54
          unsigned char c = buf[i];
 
55
 
 
56
          if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
 
57
            grub_printf ("%c", c);
 
58
          else
 
59
            {
 
60
              grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
 
61
              grub_printf ("<%x>", (int) c);
 
62
              grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
63
            }
 
64
        }
 
65
    }
 
66
 
 
67
  grub_xputs ("\n");
 
68
  grub_refresh ();
 
69
  grub_file_close (file);
 
70
 
 
71
  return 0;
 
72
}
 
73
 
 
74
/* help */
 
75
static grub_err_t
 
76
grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
 
77
                    int argc __attribute__ ((unused)),
 
78
                    char *argv[] __attribute__ ((unused)))
 
79
{
 
80
  grub_command_t p;
 
81
 
 
82
  for (p = grub_command_list; p; p = p->next)
 
83
    grub_printf ("%s (%d%c)\t%s\n", p->name,
 
84
                 p->prio & GRUB_PRIO_LIST_PRIO_MASK,
 
85
                 (p->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) ? '+' : '-',
 
86
                 p->description);
 
87
 
 
88
  return 0;
 
89
}
 
90
 
 
91
#if 0
 
92
static void
 
93
grub_rescue_cmd_info (void)
 
94
{
 
95
  extern void grub_disk_cache_get_performance (unsigned long *,
 
96
                                               unsigned long *);
 
97
  unsigned long hits, misses;
 
98
 
 
99
  grub_disk_cache_get_performance (&hits, &misses);
 
100
  grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
 
101
  if (hits + misses)
 
102
    {
 
103
      unsigned long ratio = hits * 10000 / (hits + misses);
 
104
      grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
 
105
    }
 
106
  else
 
107
    grub_printf ("(N/A)\n");
 
108
}
 
109
#endif
 
110
 
 
111
/* dump ADDRESS [SIZE] */
 
112
static grub_err_t
 
113
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
 
114
                    int argc, char *argv[])
 
115
{
 
116
  grub_uint8_t *addr;
 
117
  grub_size_t size = 4;
 
118
 
 
119
  if (argc == 0)
 
120
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no address specified");
 
121
 
 
122
  addr = (grub_uint8_t *) grub_strtoul (argv[0], 0, 0);
 
123
  if (grub_errno)
 
124
    return grub_errno;
 
125
 
 
126
  if (argc > 1)
 
127
    size = (grub_size_t) grub_strtoul (argv[1], 0, 0);
 
128
 
 
129
  while (size--)
 
130
    {
 
131
      grub_printf ("%x%x ", *addr >> 4, *addr & 0xf);
 
132
      addr++;
 
133
    }
 
134
 
 
135
  return 0;
 
136
}
 
137
 
 
138
/* rmmod MODULE */
 
139
static grub_err_t
 
140
grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
 
141
                     int argc, char *argv[])
 
142
{
 
143
  grub_dl_t mod;
 
144
 
 
145
  if (argc == 0)
 
146
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
 
147
 
 
148
  mod = grub_dl_get (argv[0]);
 
149
  if (! mod)
 
150
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
 
151
 
 
152
  if (grub_dl_unref (mod) <= 0)
 
153
    grub_dl_unload (mod);
 
154
 
 
155
  return 0;
 
156
}
 
157
 
 
158
/* lsmod */
 
159
static grub_err_t
 
160
grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
 
161
                     int argc __attribute__ ((unused)),
 
162
                     char *argv[] __attribute__ ((unused)))
 
163
{
 
164
  grub_dl_t mod;
 
165
 
 
166
  grub_printf ("Name\tRef Count\tDependencies\n");
 
167
  FOR_DL_MODULES (mod)
 
168
  {
 
169
    grub_dl_dep_t dep;
 
170
 
 
171
    grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
 
172
    for (dep = mod->dep; dep; dep = dep->next)
 
173
      {
 
174
        if (dep != mod->dep)
 
175
          grub_xputs (",");
 
176
 
 
177
        grub_printf ("%s", dep->mod->name);
 
178
      }
 
179
    grub_xputs ("\n");
 
180
  }
 
181
 
 
182
  return 0;
 
183
}
 
184
 
 
185
/* exit */
 
186
static grub_err_t
 
187
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
 
188
                    int argc __attribute__ ((unused)),
 
189
                    char *argv[] __attribute__ ((unused)))
 
190
{
 
191
  grub_exit ();
 
192
  return 0;
 
193
}
 
194
 
 
195
static grub_command_t cmd_cat, cmd_help;
 
196
static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit;
 
197
 
 
198
GRUB_MOD_INIT(minicmd)
 
199
{
 
200
  cmd_cat =
 
201
    grub_register_command ("cat", grub_mini_cmd_cat,
 
202
                           N_("FILE"), N_("Show the contents of a file."));
 
203
  cmd_help =
 
204
    grub_register_command ("help", grub_mini_cmd_help,
 
205
                           0, N_("Show this message."));
 
206
  cmd_dump =
 
207
    grub_register_command ("dump", grub_mini_cmd_dump,
 
208
                           N_("ADDR"), N_("Dump memory."));
 
209
  cmd_rmmod =
 
210
    grub_register_command ("rmmod", grub_mini_cmd_rmmod,
 
211
                           N_("MODULE"), N_("Remove a module."));
 
212
  cmd_lsmod =
 
213
    grub_register_command ("lsmod", grub_mini_cmd_lsmod,
 
214
                           0, N_("Show loaded modules."));
 
215
  cmd_exit =
 
216
    grub_register_command ("exit", grub_mini_cmd_exit,
 
217
                           0, N_("Exit from GRUB."));
 
218
}
 
219
 
 
220
GRUB_MOD_FINI(minicmd)
 
221
{
 
222
  grub_unregister_command (cmd_cat);
 
223
  grub_unregister_command (cmd_help);
 
224
  grub_unregister_command (cmd_dump);
 
225
  grub_unregister_command (cmd_rmmod);
 
226
  grub_unregister_command (cmd_lsmod);
 
227
  grub_unregister_command (cmd_exit);
 
228
}