]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2004-10-13 Hollis Blanchard <hollis@penguinppc.org>
authorhollisb <hollisb@localhost>
Wed, 13 Oct 2004 23:43:44 +0000 (23:43 +0000)
committerhollisb <hollisb@localhost>
Wed, 13 Oct 2004 23:43:44 +0000 (23:43 +0000)
    * 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.

ChangeLog
boot/powerpc/ieee1275/ieee1275.c
disk/powerpc/ieee1275/ofdisk.c
include/grub/powerpc/ieee1275/ieee1275.h
kern/powerpc/ieee1275/openfw.c

index a0e3e40e0224678a1e8bffd49abf1d14eb1c71c0..485327fd5acc4e44e6df58f07e319f0ff15eaaa4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 93bdfcfacbb5c9e7c41c712de98ba59046b73305..dcf88cd182781c78cfb7d5221dfdf4721d783baa 100644 (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;
 }
 
index b70d8931280e358237bce90605f5c577cdeb22bb..10334499d45b3bf8a2a6a4340857bcfc2b629343 100644 (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;
index 35ae94d71a5376fc62449edfd52faf7524ae0c4d..cfcf286a7000015190f161e7505f02e39f1c94ea 100644 (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 */
index eb741a7b1bb7733f78971d526318976b6fb67fbb..43297835fa709d29cddb0d3394b72320d123a3ec 100644 (file)
 #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