2004-10-13 Hollis Blanchard <hollis@penguinppc.org>

* disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_iterate):
    Call grub_children_iterate for device nodes of type `scsi',
    `ide', or `ata'.
    (grub_ofdisk_open): Remove manual device alias resolution.
    Fix memory leak when device cannot be opened.
    * include/grub/powerpc/ieee1275/ieee1275.h
    (grub_children_iterate): New prototype.
    * kern/powerpc/ieee1275/openfw.c (grub_children_iterate):
    New function.
    * boot/powerpc/ieee1275/ieee1275.c (grub_ieee1275_get_property):
    Return -1 if args.size was -1.
This commit is contained in:
hollisb 2004-10-13 23:43:44 +00:00
parent 4512e4f355
commit d1923dc8f2
5 changed files with 82 additions and 12 deletions

View file

@ -30,6 +30,11 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
{
if (! grub_strcmp (alias->type, "block"))
hook (alias->name);
else if ((! grub_strcmp (alias->type, "scsi"))
|| (! grub_strcmp (alias->type, "ide"))
|| (! grub_strcmp (alias->type, "ata")))
/* Search for block-type children of these bus controllers. */
grub_children_iterate (alias->name, dev_iterate);
return 0;
}
@ -40,31 +45,25 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
static grub_err_t
grub_ofdisk_open (const char *name, grub_disk_t disk)
{
grub_ieee1275_phandle_t devalias;
grub_ieee1275_phandle_t dev;
grub_ieee1275_ihandle_t dev_ihandle = 0;
char *devpath = 0;
/* XXX: This should be large enough for any possible case. */
char prop[64];
grub_size_t pathlen;
int actual;
if (grub_ieee1275_finddevice ("/aliases", &devalias))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't read the aliases");
grub_ieee1275_get_property_length (devalias, name, &pathlen);
devpath = grub_malloc (pathlen);
devpath = grub_strndup (name, grub_strlen (devpath) + 2);
if (! devpath)
return grub_errno;
if (grub_ieee1275_get_property (devalias, name, devpath, pathlen, &actual))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device alias");
/* To access the complete disk add `:0'. */
grub_strcat (devpath, ":0");
grub_ieee1275_open (devpath, &dev_ihandle);
if (! dev_ihandle)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't open device");
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't open device");
goto fail;
}
if (grub_ieee1275_finddevice (devpath, &dev))
{
@ -99,7 +98,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
disk->data = (void *) dev_ihandle;
fail:
if (grub_errno)
if (grub_errno && dev_ihandle)
grub_ieee1275_close (dev_ihandle);
grub_free (devpath);
return grub_errno;