1 /* grub-probe.c - probe device information for a given path */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
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.
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.
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/>.
21 #include <grub/types.h>
22 #include <grub/emu/misc.h>
23 #include <grub/util/misc.h>
24 #include <grub/device.h>
25 #include <grub/disk.h>
26 #include <grub/file.h>
28 #include <grub/partition.h>
29 #include <grub/msdos_partition.h>
30 #include <grub/emu/hostdisk.h>
31 #include <grub/emu/getroot.h>
32 #include <grub/term.h>
34 #include <grub/diskfilter.h>
35 #include <grub/i18n.h>
36 #include <grub/crypto.h>
37 #include <grub/cryptodisk.h>
38 #include <grub/hfsplus.h>
48 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
49 #pragma GCC diagnostic ignored "-Wmissing-declarations"
51 #pragma GCC diagnostic error "-Wmissing-prototypes"
52 #pragma GCC diagnostic error "-Wmissing-declarations"
57 bless (const char *path
, int x86
)
59 char *drive_name
= NULL
;
61 char *grub_path
= NULL
;
62 char *filebuf_via_grub
= NULL
, *filebuf_via_sys
= NULL
;
63 grub_device_t dev
= NULL
;
67 grub_path
= canonicalize_file_name (path
);
69 if (stat (grub_path
, &st
) < 0)
70 grub_util_error (N_("cannot stat `%s': %s"),
71 grub_path
, strerror (errno
));
73 devices
= grub_guess_root_devices (grub_path
);
75 if (! devices
|| !devices
[0])
76 grub_util_error (_("cannot find a device for %s (is /dev mounted?)"), path
);
78 drive_name
= grub_util_get_grub_dev (devices
[0]);
80 grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
83 grub_util_info ("opening %s", drive_name
);
84 dev
= grub_device_open (drive_name
);
86 grub_util_error ("%s", grub_errmsg
);
88 err
= grub_mac_bless_inode (dev
, st
.st_ino
, S_ISDIR (st
.st_mode
), x86
);
90 grub_util_error ("%s", grub_errmsg
);
92 free (filebuf_via_grub
);
93 free (filebuf_via_sys
);
96 grub_device_close (dev
);
99 static struct argp_option options
[] = {
101 N_("bless for x86-based macs"), 0},
103 N_("bless for ppc-based macs"), 0},
104 {"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
115 argp_parser (int key
, char *arg
, struct argp_state
*state
)
117 /* Get the input argument from argp_parse, which we
118 know is a pointer to our arguments structure. */
119 struct arguments
*arguments
= state
->input
;
135 case ARGP_KEY_NO_ARGS
:
136 fprintf (stderr
, "%s", _("No path or device is specified.\n"));
143 fprintf (stderr
, _("Unknown extra argument `%s'."), arg
);
144 fprintf (stderr
, "\n");
145 return ARGP_ERR_UNKNOWN
;
147 arguments
->arg
= xstrdup (arg
);
151 return ARGP_ERR_UNKNOWN
;
156 static struct argp argp
= {
157 options
, argp_parser
, N_("--ppc PATH|--x86 FILE"),
158 N_("Mac-style bless on HFS or HFS+"),
163 main (int argc
, char *argv
[])
165 struct arguments arguments
;
167 grub_util_host_init (&argc
, &argv
);
169 /* Check for options. */
170 memset (&arguments
, 0, sizeof (struct arguments
));
171 if (argp_parse (&argp
, argc
, argv
, 0, 0, &arguments
) != 0)
173 fprintf (stderr
, "%s", _("Error in parsing command line arguments\n"));
178 grub_env_set ("debug", "all");
180 /* Initialize the emulated biosdisk driver. */
181 grub_util_biosdisk_init (NULL
);
183 /* Initialize all modules. */
185 grub_gcry_init_all ();
188 grub_mdraid09_fini ();
189 grub_mdraid1x_fini ();
190 grub_diskfilter_fini ();
191 grub_diskfilter_init ();
192 grub_mdraid09_init ();
193 grub_mdraid1x_init ();
197 bless (arguments
.arg
, !arguments
.ppc
);
199 /* Free resources. */
200 grub_gcry_fini_all ();
202 grub_util_biosdisk_fini ();