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

« back to all changes in this revision

Viewing changes to commands/probe.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) 2009  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 <grub/types.h>
20
 
#include <grub/misc.h>
21
 
#include <grub/mm.h>
22
 
#include <grub/err.h>
23
 
#include <grub/dl.h>
24
 
#include <grub/device.h>
25
 
#include <grub/disk.h>
26
 
#include <grub/partition.h>
27
 
#include <grub/net.h>
28
 
#include <grub/fs.h>
29
 
#include <grub/file.h>
30
 
#include <grub/misc.h>
31
 
#include <grub/env.h>
32
 
#include <grub/extcmd.h>
33
 
#include <grub/i18n.h>
34
 
 
35
 
static const struct grub_arg_option options[] =
36
 
  {
37
 
    {"set",             's', GRUB_ARG_OPTION_OPTIONAL,
38
 
     N_("Set a variable to return value."), "VAR", ARG_TYPE_STRING},
39
 
    {"driver",          'd', 0, N_("Determine driver."), 0, 0},
40
 
    {"partmap",         'p', 0, N_("Determine partition map type."), 0, 0},
41
 
    {"fs",              'f', 0, N_("Determine filesystem type."), 0, 0},
42
 
    {"fs-uuid",         'u', 0, N_("Determine filesystem UUID."), 0, 0},
43
 
    {"label",           'l', 0, N_("Determine filesystem label."), 0, 0},
44
 
    {0, 0, 0, 0, 0, 0}
45
 
  };
46
 
 
47
 
static grub_err_t
48
 
grub_cmd_probe (grub_extcmd_t cmd, int argc, char **args)
49
 
{
50
 
  struct grub_arg_list *state = cmd->state;
51
 
  grub_device_t dev;
52
 
  grub_fs_t fs;
53
 
  char *ptr;
54
 
  grub_err_t err;
55
 
 
56
 
  if (argc < 1)
57
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
58
 
 
59
 
  ptr = args[0] + grub_strlen (args[0]) - 1;
60
 
  if (args[0][0] == '(' && *ptr == ')')
61
 
    {
62
 
      *ptr = 0;
63
 
      dev = grub_device_open (args[0] + 1);
64
 
      *ptr = ')';
65
 
    }
66
 
  else
67
 
    dev = grub_device_open (args[0]);
68
 
  if (! dev)
69
 
    return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't open device");
70
 
 
71
 
  if (state[1].set)
72
 
    {
73
 
      const char *val = "none";
74
 
      if (dev->net)
75
 
        val = dev->net->dev->name;
76
 
      if (dev->disk)
77
 
        val = dev->disk->dev->name;
78
 
      if (state[0].set)
79
 
        grub_env_set (state[0].arg, val);
80
 
      else
81
 
        grub_printf ("%s", val);
82
 
      return GRUB_ERR_NONE;
83
 
    }
84
 
  if (state[2].set)
85
 
    {
86
 
      const char *val = "none";
87
 
      if (dev->disk && dev->disk->partition)
88
 
        val = dev->disk->partition->partmap->name;
89
 
      if (state[0].set)
90
 
        grub_env_set (state[0].arg, val);
91
 
      else
92
 
        grub_printf ("%s", val);
93
 
      return GRUB_ERR_NONE;
94
 
    }
95
 
  fs = grub_fs_probe (dev);
96
 
  if (! fs)
97
 
    return grub_error (GRUB_ERR_UNKNOWN_FS, "unrecognised fs");
98
 
  if (state[3].set)
99
 
    {
100
 
      if (state[0].set)
101
 
        grub_env_set (state[0].arg, fs->name);
102
 
      else
103
 
        grub_printf ("%s", fs->name);
104
 
      return GRUB_ERR_NONE;
105
 
    }
106
 
  if (state[4].set)
107
 
    {
108
 
      char *uuid;
109
 
      if (! fs->uuid)
110
 
        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
111
 
                           "uuid for this FS isn't supported yet");
112
 
      err = fs->uuid (dev, &uuid);
113
 
      if (err)
114
 
        return err;
115
 
      if (! uuid)
116
 
        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
117
 
                           "uuid for this FS isn't supported yet");
118
 
 
119
 
      if (state[0].set)
120
 
        grub_env_set (state[0].arg, uuid);
121
 
      else
122
 
        grub_printf ("%s", uuid);
123
 
      grub_free (uuid);
124
 
      return GRUB_ERR_NONE;
125
 
    }
126
 
  if (state[5].set)
127
 
    {
128
 
      char *label;
129
 
      if (! fs->label)
130
 
        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
131
 
                           "label for this FS isn't supported yet");
132
 
      err = fs->label (dev, &label);
133
 
      if (err)
134
 
        return err;
135
 
      if (! label)
136
 
        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
137
 
                           "uuid for this FS isn't supported yet");
138
 
 
139
 
      if (state[0].set)
140
 
        grub_env_set (state[0].arg, label);
141
 
      else
142
 
        grub_printf ("%s", label);
143
 
      grub_free (label);
144
 
      return GRUB_ERR_NONE;
145
 
    }
146
 
  return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target");
147
 
}
148
 
 
149
 
static grub_extcmd_t cmd;
150
 
 
151
 
GRUB_MOD_INIT (probe)
152
 
{
153
 
  cmd = grub_register_extcmd ("probe", grub_cmd_probe, GRUB_COMMAND_FLAG_BOTH,
154
 
                              N_("[DEVICE]"),
155
 
                              N_("Retrieve device info."), options);
156
 
}
157
 
 
158
 
GRUB_MOD_FINI (probe)
159
 
{
160
 
  grub_unregister_extcmd (cmd);
161
 
}