grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ppc patch] support SCSI disks


From: Hollis Blanchard
Subject: Re: [ppc patch] support SCSI disks
Date: Sun, 3 Oct 2004 18:06:24 -0500 (CDT)

I've tested this patch on a B&W G3, and as expected it listed both "hd" 
and "ide1/disk" as present disks. Please apply.

2004-10-01      Hollis Blanchard        <address@hidden>

        * 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.
        Fix error checking after grub_ieee1275_get_property.
        * include/grub/powerpc/ieee1275/ieee1275.h 
        (grub_children_iterate): new prototype.
        * kern/powerpc/ieee1275/openfw.c (grub_children_iterate):
        new function.

Index: disk/powerpc/ieee1275/ofdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/disk/powerpc/ieee1275/ofdisk.c,v
retrieving revision 1.3
diff -u -r1.3 ofdisk.c
--- disk/powerpc/ieee1275/ofdisk.c      21 Aug 2004 13:54:22 -0000      1.3
+++ disk/powerpc/ieee1275/ofdisk.c      3 Oct 2004 22:54:59 -0000
@@ -30,6 +30,11 @@
     {
       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 @@
 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))
     {
@@ -72,8 +71,9 @@
       goto fail;
     }
 
-  if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
-                                 &actual))
+  grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
+                                 &actual);
+  if (actual == -1)
     {
       grub_error (GRUB_ERR_BAD_DEVICE, "Can't read the device type");
       goto fail;
@@ -99,7 +99,7 @@
   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: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v
retrieving revision 1.5
diff -u -r1.5 ieee1275.h
--- include/grub/powerpc/ieee1275/ieee1275.h    3 Oct 2004 09:19:10 -0000       
1.5
+++ include/grub/powerpc/ieee1275/ieee1275.h    3 Oct 2004 22:54:59 -0000
@@ -96,6 +96,8 @@
 
 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: kern/powerpc/ieee1275/openfw.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/openfw.c,v
retrieving revision 1.2
diff -u -r1.2 openfw.c
--- kern/powerpc/ieee1275/openfw.c      4 Apr 2004 13:46:02 -0000       1.2
+++ kern/powerpc/ieee1275/openfw.c      3 Oct 2004 22:54:59 -0000
@@ -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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]