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

@ -1,3 +1,17 @@
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.
2004-10-11 Hollis Blanchard <hollis@penguinppc.org>
* boot/powerpc/ieee1275/cmain.c (grub_ieee1275_flags): New global.

View File

@ -98,6 +98,8 @@ grub_ieee1275_get_property (grub_ieee1275_phandle_t handle,
return -1;
if (actual)
*actual = args.size;
if (args.size == -1)
return -1;
return 0;
}

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;

View File

@ -101,6 +101,8 @@ int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
grub_err_t EXPORT_FUNC(grub_devalias_iterate)
(int (*hook) (struct grub_ieee1275_devalias *alias));
grub_err_t EXPORT_FUNC(grub_children_iterate) (char *devpath,
int (*hook) (struct grub_ieee1275_devalias *alias));
#endif /* ! GRUB_IEEE1275_MACHINE_HEADER */

View File

@ -23,6 +23,59 @@
#include <grub/mm.h>
#include <grub/machine/ieee1275.h>
/* Walk children of 'devpath', calling hook for each. */
grub_err_t
grub_children_iterate (char *devpath,
int (*hook) (struct grub_ieee1275_devalias *alias))
{
grub_ieee1275_phandle_t dev;
grub_ieee1275_phandle_t child;
grub_ieee1275_finddevice (devpath, &dev);
if (dev == -1)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown device");
grub_ieee1275_child (dev, &child);
if (child == -1)
return grub_error (GRUB_ERR_BAD_DEVICE, "Device has no children");
do
{
/* XXX: Don't use hardcoded path lengths. */
char childtype[64];
char childpath[64];
char childname[64];
char fullname[64];
struct grub_ieee1275_devalias alias;
int actual;
grub_ieee1275_get_property (child, "device_type", &childtype,
sizeof childtype, &actual);
if (actual == -1)
continue;
grub_ieee1275_package_to_path (child, childpath, sizeof childpath,
&actual);
if (actual == -1)
continue;
grub_ieee1275_get_property (child, "name", &childname,
sizeof childname, &actual);
if (actual == -1)
continue;
grub_sprintf(fullname, "%s/%s", devpath, childname);
alias.type = childtype;
alias.path = childpath;
alias.name = fullname;
hook (&alias);
}
while (grub_ieee1275_peer (child, &child));
return 0;
}
/* Iterate through all device aliasses. Thisfunction can be used to
find a device of a specific type. */
grub_err_t