Beispiel #1
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);
}
Beispiel #2
0
static void
scan (void)
{
  struct grub_ieee1275_devalias alias;
  FOR_IEEE1275_DEVALIASES(alias)
    {
      if (grub_strcmp (alias.type, "block") != 0)
	continue;
      dev_iterate_real (alias.name, alias.path);
    }

  FOR_IEEE1275_DEVCHILDREN("/", alias)
    dev_iterate (&alias);
}
Beispiel #3
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);
}
Beispiel #4
0
static void
dev_iterate (const 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;

      /* This method doesn't need memory allocation for the table. Open
         firmware takes care of all memory management and the result table
         stays in memory and is never freed. */
      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 || args.catch_result)
	{
	  grub_ieee1275_close (ihandle);
	  return;
	}

      buf = grub_malloc (grub_strlen (alias->path) + 32);
      if (!buf)
	return;
      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++);
	      dev_iterate_real (buf, buf);
	    }
	}
      grub_ieee1275_close (ihandle);
      grub_free (buf);
      return;
    }
  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
    {
      /* The method returns the number of disks and a table where
       * each ID is 64-bit long. Example of sas paths:
       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */

      struct sas_children
        {
          struct grub_ieee1275_common_hdr common;
          grub_ieee1275_cell_t method;
          grub_ieee1275_cell_t ihandle;
          grub_ieee1275_cell_t max;
          grub_ieee1275_cell_t table;
          grub_ieee1275_cell_t catch_result;
          grub_ieee1275_cell_t nentries;
        }
      args;
      char *buf, *bufptr;
      unsigned i;
      grub_uint64_t *table;
      grub_uint16_t table_size;
      grub_ieee1275_ihandle_t ihandle;

      buf = grub_malloc (grub_strlen (alias->path) +
                         sizeof ("/disk@7766554433221100"));
      if (!buf)
        return;
      bufptr = grub_stpcpy (buf, alias->path);

      /* Power machines documentation specify 672 as maximum SAS disks in
         one system. Using a slightly larger value to be safe. */
      table_size = 768;
      table = grub_malloc (table_size * sizeof (grub_uint64_t));

      if (!table)
        {
          grub_free (buf);
          return;
        }

      if (grub_ieee1275_open (alias->path, &ihandle))
        {
          grub_free (buf);
          grub_free (table);
          return;
        }

      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
      args.method = (grub_ieee1275_cell_t) "get-sas-children";
      args.ihandle = ihandle;
      args.max = table_size;
      args.table = (grub_ieee1275_cell_t) table;
      args.catch_result = 0;
      args.nentries = 0;

      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
        {
          grub_ieee1275_close (ihandle);
          grub_free (table);
          grub_free (buf);
          return;
        }

      for (i = 0; i < args.nentries; i++)
        {
          grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"),
                        "/disk@%" PRIxGRUB_UINT64_T, table[i]);
          dev_iterate_real (buf, buf);
        }

      grub_ieee1275_close (ihandle);
      grub_free (table);
      grub_free (buf);
    }

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

  {
    struct grub_ieee1275_devalias child;

    FOR_IEEE1275_DEVCHILDREN(alias->path, child)
      dev_iterate (&child);
  }
}
Beispiel #5
0
static void
dev_iterate (const 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;
    
      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 || args.catch_result)
	{
	  grub_ieee1275_close (ihandle);
	  return;
	}

      buf = grub_malloc (grub_strlen (alias->path) + 32);
      if (!buf)
	return;
      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++);
	      dev_iterate_real (buf, buf);
	    }
	}
      grub_ieee1275_close (ihandle);
      grub_free (buf);
      return;
    }

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

  {
    struct grub_ieee1275_devalias child;

    FOR_IEEE1275_DEVCHILDREN(alias->path, child)
      dev_iterate (&child);
  }
}