Exemple #1
0
static int
fill_alias (struct grub_ieee1275_devalias *alias)
{
  grub_ssize_t actual;

  if (grub_ieee1275_get_property (alias->phandle, "device_type", alias->type,
				  IEEE1275_MAX_PROP_LEN, &actual))
    alias->type[0] = 0;

  if (alias->parent_dev == alias->phandle)
    return 0;

  if (grub_ieee1275_package_to_path (alias->phandle, alias->path,
				     IEEE1275_MAX_PATH_LEN, &actual))
    return 0;

  if (grub_strcmp (alias->parent_path, alias->path) == 0)
    return 0;

  if (grub_ieee1275_get_property (alias->phandle, "name", alias->name,
				  IEEE1275_MAX_PROP_LEN, &actual))
    return 0;
  grub_dprintf ("devalias", "device path=%s\n", alias->path);
  return 1;
}
Exemple #2
0
/* 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;

  if (grub_ieee1275_finddevice (devpath, &dev))
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown device");

  if (grub_ieee1275_child (dev, &child))
    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;

      if (grub_ieee1275_get_property (child, "device_type", &childtype,
				      sizeof childtype, &actual))
	continue;

      if (grub_ieee1275_package_to_path (child, childpath, sizeof childpath,
					 &actual))
	continue;

      if (grub_ieee1275_get_property (child, "name", &childname,
				      sizeof childname, &actual))
	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;
}
Exemple #3
0
/* Walk children of 'devpath', calling hook for each.  */
int
grub_children_iterate (char *devpath,
		       int (*hook) (struct grub_ieee1275_devalias *alias,
				    void *closure),
		       void *closure)
{
  grub_ieee1275_phandle_t dev;
  grub_ieee1275_phandle_t child;
  char *childtype, *childpath;
  char *childname;
  int ret = 0;

  if (grub_ieee1275_finddevice (devpath, &dev))
    return 0;

  if (grub_ieee1275_child (dev, &child))
    return 0;

  childtype = grub_malloc (IEEE1275_MAX_PROP_LEN);
  if (!childtype)
    return 0;
  childpath = grub_malloc (IEEE1275_MAX_PATH_LEN);
  if (!childpath)
    {
      grub_free (childtype);
      return 0;
    }
  childname = grub_malloc (IEEE1275_MAX_PROP_LEN);
  if (!childname)
    {
      grub_free (childpath);
      grub_free (childtype);
      return 0;
    }

  do
    {
      struct grub_ieee1275_devalias alias;
      grub_ssize_t actual;

      if (grub_ieee1275_get_property (child, "device_type", childtype,
				      IEEE1275_MAX_PROP_LEN, &actual))
	childtype[0] = 0;

      if (dev == child)
	continue;

      if (grub_ieee1275_package_to_path (child, childpath,
					 IEEE1275_MAX_PATH_LEN, &actual))
	continue;

      if (grub_strcmp (devpath, childpath) == 0)
	continue;

      if (grub_ieee1275_get_property (child, "name", childname,
				      IEEE1275_MAX_PROP_LEN, &actual))
	continue;

      alias.type = childtype;
      alias.path = childpath;
      alias.name = childname;
      ret = hook (&alias, closure);
      if (ret)
	break;
    }
  while (grub_ieee1275_peer (child, &child) != -1);

  grub_free (childname);
  grub_free (childpath);
  grub_free (childtype);

  return ret;
}