Allow override Plan9 device names

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-12-21 00:22:11 +01:00
parent da94d203d9
commit 645b8cd99f

View file

@ -32,6 +32,7 @@
#include <grub/video.h>
#include <grub/mm.h>
#include <grub/cpu/relocator.h>
#include <grub/extcmd.h>
static grub_dl_t my_mod;
static struct grub_relocator *rel;
@ -43,6 +44,14 @@ static grub_uint32_t eip = 0xffffffff;
#define GRUB_PLAN9_CONFIG_PATH_SIZE 0x000040
#define GRUB_PLAN9_CONFIG_MAGIC "ZORT 0\r\n"
static const struct grub_arg_option options[] =
{
{"map", 'm', GRUB_ARG_OPTION_REPEATABLE,
N_("Override guessed mapping of Plan9 devices."), "GRUBDEVICE=PLAN9DEVICE",
ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
struct grub_plan9_header
{
grub_uint32_t magic;
@ -85,8 +94,7 @@ grub_plan9_unload (void)
}
static grub_err_t
grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
{
grub_file_t file = 0;
void *mem;
@ -94,7 +102,6 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
struct grub_plan9_header hdr;
char *config, *configptr;
grub_size_t configsize;
int i;
char *pmap = NULL;
grub_size_t pmapalloc = 256;
grub_size_t pmapptr = 0;
@ -193,6 +200,7 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
grub_device_t dev;
int file_disk;
char *plan9name = NULL;
unsigned i;
dev = grub_device_open (name);
if (!dev)
@ -207,6 +215,13 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
}
file_disk = file->device->disk && dev->disk->id == file->device->disk->id
&& dev->disk->dev->id == file->device->disk->dev->id;
for (i = 0; ctxt->state[0].args && ctxt->state[0].args[i]; i++)
if (grub_strncmp (name, ctxt->state[0].args[i], grub_strlen (name)) == 0
&& ctxt->state[0].args[i][grub_strlen (name)] == '=')
break;
if (ctxt->state[0].args && ctxt->state[0].args[i])
plan9name = grub_strdup (ctxt->state[0].args[i] + grub_strlen (name) + 1);
else
switch (dev->disk->dev->id)
{
case GRUB_DISK_DEVICE_BIOSDISK_ID:
@ -261,7 +276,8 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
if (grub_strlen (dev->disk->name) < sizeof ("ata0") - 1)
unit = 0;
else
unit = grub_strtoul (dev->disk->name + sizeof ("ata0") - 1, 0, 0);
unit = grub_strtoul (dev->disk->name + sizeof ("ata0") - 1,
0, 0);
plan9name = grub_xasprintf ("sd%c%d", 'C' + unit / 2, unit % 2);
break;
}
@ -270,7 +286,8 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
We probably need save the SCSI devices and sort them */
plan9name
= grub_xasprintf ("sd0%u", (unsigned)
((dev->disk->id >> GRUB_SCSI_ID_BUS_SHIFT) & 0xf));
((dev->disk->id >> GRUB_SCSI_ID_BUS_SHIFT)
& 0xf));
break;
}
if (!plan9name)
@ -347,8 +364,11 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
configsize = GRUB_PLAN9_CONFIG_PATH_SIZE;
/* magic */
configsize += sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1;
{
int i;
for (i = 1; i < argc; i++)
configsize += grub_strlen (argv[i]) + 1;
}
configsize += pmapptr;
/* Terminating \0. */
configsize++;
@ -368,11 +388,14 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
grub_memcpy (configptr, GRUB_PLAN9_CONFIG_MAGIC,
sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1);
configptr += sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1;
{
int i;
for (i = 1; i < argc; i++)
{
configptr = grub_stpcpy (configptr, argv[i]);
*configptr++ = '\n';
}
}
configptr = grub_stpcpy (configptr, pmap);
{
@ -429,16 +452,18 @@ grub_cmd_plan9 (grub_command_t cmd __attribute__ ((unused)),
return grub_errno;
}
static grub_command_t cmd;
static grub_extcmd_t cmd;
GRUB_MOD_INIT(plan9)
{
cmd = grub_register_command ("plan9", grub_cmd_plan9,
0, N_("Load Plan9 kernel."));
cmd = grub_register_extcmd ("plan9", grub_cmd_plan9,
GRUB_COMMAND_OPTIONS_AT_START,
N_("KERNEL ARGS"), N_("Load Plan9 kernel."),
options);
my_mod = mod;
}
GRUB_MOD_FINI(plan9)
{
grub_unregister_command (cmd);
grub_unregister_extcmd (cmd);
}