Пример #1
0
static grub_err_t
grub_ofdisk_open (const char *name, grub_disk_t disk)
{
  grub_ieee1275_phandle_t dev;
  char *devpath;
  /* XXX: This should be large enough for any possible case.  */
  char prop[64];
  grub_ssize_t actual;

  if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0)
      return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
			 "not IEEE1275 device");
  devpath = compute_dev_path (name + sizeof ("ieee1275/") - 1);
  if (! devpath)
    return grub_errno;

  grub_dprintf ("disk", "Opening `%s'.\n", devpath);

  if (grub_ieee1275_finddevice (devpath, &dev))
    {
      grub_free (devpath);
      return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
			 "can't read device properties");
    }

  if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
				  &actual))
    {
      grub_free (devpath);
      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
    }

  if (grub_strcmp (prop, "block"))
    {
      grub_free (devpath);
      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
    }

  /* XXX: There is no property to read the number of blocks.  There
     should be a property `#blocks', but it is not there.  Perhaps it
     is possible to use seek for this.  */
  disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;

  {
    struct ofdisk_hash_ent *op;
    op = ofdisk_hash_find (devpath);
    if (!op)
      op = ofdisk_hash_add (devpath, NULL);
    else
      grub_free (devpath);
    if (!op)
      return grub_errno;
    disk->id = (unsigned long) op;
    disk->data = op->devpath;
  }

  return 0;
}
Пример #2
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);
}
Пример #3
0
static void
insert_bootpath (void)
{
  char *bootpath;
  grub_ssize_t bootpath_size;
  char *type;

  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
					 &bootpath_size)
      || bootpath_size <= 0)
    {
      /* Should never happen.  */
      grub_printf ("/chosen/bootpath property missing!\n");
      return;
    }

  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
  if (! bootpath)
    {
      grub_print_error ();
      return;
    }
  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
                              (grub_size_t) bootpath_size + 1, 0);
  bootpath[bootpath_size] = '\0';

  /* Transform an OF device path to a GRUB path.  */

  type = grub_ieee1275_get_device_type (bootpath);
  if (!(type && grub_strcmp (type, "network") == 0))
    {
      struct ofdisk_hash_ent *op;
      char *device = grub_ieee1275_get_devname (bootpath);
      op = ofdisk_hash_add (device, NULL);
      op->is_boot = 1;
    }
  grub_free (type);
  grub_free (bootpath);
}
Пример #4
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);
}
Пример #5
0
static void
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;
	}
      op = ofdisk_hash_add (name_dup, can);
    }
  return;
}
Пример #6
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);
}
Пример #7
0
static grub_err_t
grub_ofdisk_open (const char *name, grub_disk_t disk)
{
  grub_ieee1275_phandle_t dev;
  grub_ieee1275_ihandle_t dev_ihandle = 0;
  struct ofdisk_hash_ent *op;
  char *devpath;
  /* XXX: This should be large enough for any possible case.  */
  char prop[64];
  grub_ssize_t actual;

  devpath = compute_dev_path (name);
  if (! devpath)
    return grub_errno;

  op = ofdisk_hash_find (devpath);
  if (!op)
    op = ofdisk_hash_add (devpath);

  grub_free (devpath);
  if (!op)
    return grub_errno;

  if (op->dev_ihandle)
    {
      op->refs++;

      /* XXX: There is no property to read the number of blocks.  There
	 should be a property `#blocks', but it is not there.  Perhaps it
	 is possible to use seek for this.  */
      disk->total_sectors = 0xFFFFFFFFUL;

      disk->id = (unsigned long) op;

      /* XXX: Read this, somehow.  */
      disk->has_partitions = 1;
      disk->data = op;
      return 0;
    }

  grub_dprintf ("disk", "Opening `%s'.\n", op->devpath);

  if (grub_ieee1275_finddevice (op->devpath, &dev))
    {
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
      goto fail;
    }

  if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
				  &actual))
    {
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
      goto fail;
    }

  if (grub_strcmp (prop, "block"))
    {
      grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
      goto fail;
    }

  grub_ieee1275_open (op->devpath, &dev_ihandle);
  if (! dev_ihandle)
    {
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
      goto fail;
    }

  grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath,
		(void *) (unsigned long) dev_ihandle);

  op->dev_ihandle = dev_ihandle;
  op->refs++;

  /* XXX: There is no property to read the number of blocks.  There
     should be a property `#blocks', but it is not there.  Perhaps it
     is possible to use seek for this.  */
  disk->total_sectors = 0xFFFFFFFFUL;

  disk->id = (unsigned long) op;

  /* XXX: Read this, somehow.  */
  disk->has_partitions = 1;
  disk->data = op;
  return 0;

 fail:
  if (dev_ihandle)
    grub_ieee1275_close (dev_ihandle);
  return grub_errno;
}