2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
19
#include <grub/types.h>
20
#include <grub/misc.h>
24
#include <grub/device.h>
25
#include <grub/disk.h>
26
#include <grub/partition.h>
29
#include <grub/file.h>
30
#include <grub/misc.h>
32
#include <grub/extcmd.h>
33
#include <grub/i18n.h>
35
static const struct grub_arg_option options[] =
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},
48
grub_cmd_probe (grub_extcmd_t cmd, int argc, char **args)
50
struct grub_arg_list *state = cmd->state;
57
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
59
ptr = args[0] + grub_strlen (args[0]) - 1;
60
if (args[0][0] == '(' && *ptr == ')')
63
dev = grub_device_open (args[0] + 1);
67
dev = grub_device_open (args[0]);
69
return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't open device");
73
const char *val = "none";
75
val = dev->net->dev->name;
77
val = dev->disk->dev->name;
79
grub_env_set (state[0].arg, val);
81
grub_printf ("%s", val);
86
const char *val = "none";
87
if (dev->disk && dev->disk->partition)
88
val = dev->disk->partition->partmap->name;
90
grub_env_set (state[0].arg, val);
92
grub_printf ("%s", val);
95
fs = grub_fs_probe (dev);
97
return grub_error (GRUB_ERR_UNKNOWN_FS, "unrecognised fs");
101
grub_env_set (state[0].arg, fs->name);
103
grub_printf ("%s", fs->name);
104
return GRUB_ERR_NONE;
110
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
111
"uuid for this FS isn't supported yet");
112
err = fs->uuid (dev, &uuid);
116
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
117
"uuid for this FS isn't supported yet");
120
grub_env_set (state[0].arg, uuid);
122
grub_printf ("%s", uuid);
124
return GRUB_ERR_NONE;
130
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
131
"label for this FS isn't supported yet");
132
err = fs->label (dev, &label);
136
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
137
"uuid for this FS isn't supported yet");
140
grub_env_set (state[0].arg, label);
142
grub_printf ("%s", label);
144
return GRUB_ERR_NONE;
146
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target");
149
static grub_extcmd_t cmd;
151
GRUB_MOD_INIT (probe)
153
cmd = grub_register_extcmd ("probe", grub_cmd_probe, GRUB_COMMAND_FLAG_BOTH,
155
N_("Retrieve device info."), options);
158
GRUB_MOD_FINI (probe)
160
grub_unregister_extcmd (cmd);