grub-fstest luks support

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-04-22 19:44:41 +02:00
parent 24089d19e2
commit 4169260830
2 changed files with 39 additions and 4 deletions

View file

@ -107,6 +107,7 @@ gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src,
static const struct grub_arg_option options[] =
{
{"uuid", 'u', 0, N_("Mount by UUID."), 0, 0},
{"all", 'a', 0, N_("Mount all."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
@ -491,7 +492,11 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source)
{
grub_err_t err;
struct grub_luks_phdr header;
grub_luks_t newdev;
grub_luks_t newdev, dev;
for (dev = luks_list; dev != NULL; dev = dev->next)
if (dev->source_id == source->id && dev->source_dev_id == source->dev->id)
return GRUB_ERR_NONE;
/* Read the LUKS header. */
err = grub_disk_read (source, 0, 0, sizeof (header), &header);
@ -532,7 +537,7 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat)
{
grub_err_t err;
struct grub_luks_phdr header;
grub_luks_t newdev;
grub_luks_t newdev, dev;
grub_disk_t source;
/* Try to open disk. */
@ -540,6 +545,13 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat)
if (!source)
return grub_errno;
for (dev = luks_list; dev != NULL; dev = dev->next)
if (dev->source_id == source->id && dev->source_dev_id == source->dev->id)
{
grub_disk_close (source);
return GRUB_ERR_NONE;
}
/* Read the LUKS header. */
err = grub_disk_read (source, 0, 0, sizeof (header), &header);
if (err)
@ -755,7 +767,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
if (argc < 1)
if (argc < 1 && !state[1].set)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
have_it = 0;
@ -779,6 +791,14 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found");
return GRUB_ERR_NONE;
}
else if (state[1].set)
{
check_uuid = 0;
search_uuid = NULL;
grub_device_iterate (&grub_luks_scan_device);
search_uuid = NULL;
return GRUB_ERR_NONE;
}
else
{
grub_err_t err;
@ -823,7 +843,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT (luks)
{
cmd = grub_register_extcmd ("luksmount", grub_cmd_luksmount, 0,
N_("SOURCE|-u UUID"),
N_("SOURCE|-u UUID|-a"),
N_("Mount a LUKS device."), options);
grub_disk_dev_register (&grub_luks_dev);
}

View file

@ -275,6 +275,7 @@ static char **images = NULL;
static int cmd = 0;
static char *debug_str = NULL;
static char **args = NULL;
static int mount_crypt = 0;
static void
fstest (int n, char **args)
@ -304,6 +305,13 @@ fstest (int n, char **args)
grub_free (host_file);
}
{
char *argv[2] = { "-a", NULL};
if (mount_crypt)
if (execute_command ("luksmount", 1, argv))
grub_util_error (_("luksmount command fails: %s"), grub_errmsg);
}
grub_lvm_fini ();
grub_mdraid09_fini ();
grub_mdraid1x_fini ();
@ -366,6 +374,7 @@ static struct argp_option options[] = {
{"length", 'n', "N", 0, N_("Handle N bytes in output file."), 2},
{"diskcount", 'c', "N", 0, N_("N input files."), 2},
{"debug", 'd', "S", 0, N_("Set debug environment variable."), 2},
{"crypto", 'C', NULL, OPTION_ARG_OPTIONAL, N_("Mount crypto devices."), 2},
{"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2},
{0, 0, 0, 0, 0, 0}
};
@ -389,6 +398,10 @@ argp_parser (int key, char *arg, struct argp_state *state)
root = arg;
return 0;
case 'C':
mount_crypt = 1;
return 0;
case 's':
skip = grub_strtoul (arg, &p, 0);
if (*p == 's')
@ -523,6 +536,7 @@ main (int argc, char *argv[])
/* Initialize all modules. */
grub_init_all ();
grub_gcry_init_all ();
if (debug_str)
grub_env_set ("debug", debug_str);
@ -551,6 +565,7 @@ main (int argc, char *argv[])
fstest (args_count - 1 - num_disks, args);
/* Free resources. */
grub_gcry_fini_all ();
grub_fini_all ();
return 0;