Exemplo n.º 1
0
/* Get the device path of the Open Firmware node name `path'.  */
static char *
grub_ieee1275_get_devname (const char *path)
{
  char *colon = grub_strchr (path, ':');
  char *newpath = 0;
  int pathlen = grub_strlen (path);
  auto int match_alias (struct grub_ieee1275_devalias *alias);

  int match_alias (struct grub_ieee1275_devalias *curalias)
    {
      /* briQ firmware can change capitalization in /chosen/bootpath.  */
      if (! grub_strncasecmp (curalias->path, path, pathlen))
        {
	  newpath = grub_strdup (curalias->name);
	  return 1;
	}

      return 0;
    }

  if (colon)
    pathlen = (int)(colon - path);

  /* Try to find an alias for this device.  */
  grub_devalias_iterate (match_alias);

  if (! newpath)
    newpath = grub_strndup (path, pathlen);

  return newpath;
}
Exemplo n.º 2
0
static int
grub_ofdisk_iterate (int (*hook) (const char *name, void *closure), void *closure)
{
  struct grub_ofdisk_iterate_closure c;

  c.hook = hook;
  c.closure = closure;
  return grub_devalias_iterate (dev_iterate, &c);
}
Exemplo n.º 3
0
static void
scan (void)
{
  auto int dev_iterate_real (struct grub_ieee1275_devalias *alias,
			     int use_name);

  int dev_iterate_real (struct grub_ieee1275_devalias *alias, int use_name)
    {
      struct ofdisk_hash_ent *op;


      if (grub_strcmp (alias->type, "block") != 0)
	return 0;

      grub_dprintf ("disk", "disk name = %s, path = %s\n", alias->name,
		    alias->path);

      op = ofdisk_hash_find (alias->path);
      if (!op)
	{
	  char *name = grub_strdup (use_name ? alias->name : alias->path);
	  char *can = grub_strdup (alias->path);
	  if (!name || !can)
	    {
	      grub_errno = GRUB_ERR_NONE;
	      grub_free (name);
	      grub_free (can);
	      return 0;
	    }
	  op = ofdisk_hash_add (name, can);
	}
      return 0;
    }

  auto int dev_iterate_alias (struct grub_ieee1275_devalias *alias);
  int dev_iterate_alias (struct grub_ieee1275_devalias *alias)
  {
    return dev_iterate_real (alias, 1);
  }

  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
  int dev_iterate (struct grub_ieee1275_devalias *alias)
  {
    return dev_iterate_real (alias, 0);
  }

  grub_devalias_iterate (dev_iterate_alias);
  if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS))
    grub_ieee1275_devices_iterate (dev_iterate);
}
Exemplo n.º 4
0
static char *
find_alias (const char *fullname)
{
  char *ret = NULL;
  auto int find_alias_hook (struct grub_ieee1275_devalias *alias);

  int find_alias_hook (struct grub_ieee1275_devalias *alias)
  {
    if (grub_strcmp (alias->path, fullname) == 0)
      {
	ret = grub_strdup (alias->name);
	return 1;
      }
    return 0;
  }

  grub_devalias_iterate (find_alias_hook);
  grub_errno = GRUB_ERR_NONE;
  return ret;
}
Exemplo n.º 5
0
/* Get the device path of the Open Firmware node name `path'.  */
static char *
grub_ieee1275_get_devname (const char *path)
{
  char *colon = grub_strchr (path, ':');
  struct grub_ieee1275_get_devname_closure c;

  c.path = path;
  c.newpath = 0;
  c.pathlen = grub_strlen (path);

  if (colon)
    c.pathlen = (int)(colon - path);

  /* Try to find an alias for this device.  */
  grub_devalias_iterate (match_alias, &c);

  if (! c.newpath)
    c.newpath = grub_strndup (path, c.pathlen);

  return c.newpath;
}
Exemplo n.º 6
0
static void
scan (void)
{
  auto int dev_iterate (struct grub_ieee1275_devalias *alias);

  int dev_iterate (struct grub_ieee1275_devalias *alias)
    {
      struct ofdisk_hash_ent *op;

      grub_dprintf ("disk", "device name = %s type = %s\n", alias->name,
		    alias->type);

      if (grub_strcmp (alias->type, "block") != 0)
	return 0;

      grub_dprintf ("disk", "disk name = %s\n", alias->name);
      grub_dprintf ("disk", "disk name = %s, path = %s\n", alias->name,
		    alias->path);

      op = ofdisk_hash_find (alias->name);
      if (!op)
	{
	  char *name = grub_strdup (alias->name);
	  char *can = grub_strdup (alias->path);
	  if (!name || !can)
	    {
	      grub_errno = GRUB_ERR_NONE;
	      grub_free (name);
	      grub_free (can);
	      return 0;
	    }
	  op = ofdisk_hash_add (name, can);
	}
      return 0;
    }

  grub_devalias_iterate (dev_iterate);
  grub_ieee1275_devices_iterate (dev_iterate);
}
Exemplo n.º 7
0
static void
scan (void)
{
  auto int dev_iterate_real (const char *name, const char *path);

  int dev_iterate_real (const char *name, const char *path)
    {
      struct ofdisk_hash_ent *op;

      grub_dprintf ("disk", "disk name = %s, path = %s\n", name,
		    path);

      op = ofdisk_hash_find (path);
      if (!op)
	{
	  char *name_dup = grub_strdup (name);
	  char *can = grub_strdup (path);
	  if (!name_dup || !can)
	    {
	      grub_errno = GRUB_ERR_NONE;
	      grub_free (name_dup);
	      grub_free (can);
	      return 0;
	    }
	  op = ofdisk_hash_add (name_dup, can);
	}
      return 0;
    }

  auto int dev_iterate_alias (struct grub_ieee1275_devalias *alias);
  int dev_iterate_alias (struct grub_ieee1275_devalias *alias)
  {
    if (grub_strcmp (alias->type, "block") != 0)
      return 0;
    return dev_iterate_real (alias->name, alias->path);
  }

  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
  int dev_iterate (struct grub_ieee1275_devalias *alias)
  {
    if (grub_strcmp (alias->type, "vscsi") == 0)
      {
	static grub_ieee1275_ihandle_t ihandle;
	struct set_color_args
	{
	  struct grub_ieee1275_common_hdr common;
	  grub_ieee1275_cell_t method;
	  grub_ieee1275_cell_t ihandle;
	  grub_ieee1275_cell_t catch_result;
	  grub_ieee1275_cell_t nentries;
	  grub_ieee1275_cell_t table;
	}
	args;
	char *buf, *bufptr;
	unsigned i;

	if (grub_ieee1275_open (alias->path, &ihandle))
	  return 0;
    
	INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
	args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
	args.ihandle = ihandle;
	args.table = 0;
	args.nentries = 0;

	if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
	  {
	    grub_ieee1275_close (ihandle);
	    return 0;
	  }

	buf = grub_malloc (grub_strlen (alias->path) + 32);
	if (!buf)
	  return 0;
	bufptr = grub_stpcpy (buf, alias->path);

	for (i = 0; i < args.nentries; i++)
	  {
	    grub_uint64_t *ptr;

	    ptr = *(grub_uint64_t **) (args.table + 4 + 8 * i);
	    while (*ptr)
	      {
		grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr++);
		if (dev_iterate_real (buf, buf))
		  return 1;
	      }
	  }
	grub_ieee1275_close (ihandle);
	grub_free (buf);
	return 0;
      }

    if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
	&& grub_strcmp (alias->type, "block") == 0)
      return dev_iterate_real (alias->path, alias->path);

    return grub_children_iterate (alias->path, dev_iterate);
  }

  grub_devalias_iterate (dev_iterate_alias);
  grub_children_iterate ("/", dev_iterate);
}