Пример #1
0
static grub_err_t
grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
{
  grub_ssize_t status;
  unsigned long long pos;

  if (disk->data != last_devpath)
    {
      if (last_ihandle)
	grub_ieee1275_close (last_ihandle);
      last_ihandle = 0;
      last_devpath = NULL;

      grub_ieee1275_open (disk->data, &last_ihandle);
      if (! last_ihandle)
	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
      last_devpath = disk->data;      
    }

  pos = sector << disk->log_sector_size;

  grub_ieee1275_seek (last_ihandle, pos, &status);
  if (status < 0)
    return grub_error (GRUB_ERR_READ_ERROR,
		       "seek error, can't seek block %llu",
		       (long long) sector);
  return 0;
}
Пример #2
0
static grub_err_t
grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
		  grub_size_t size, char *buf)
{
  grub_ssize_t status, actual;
  unsigned long long pos;

  if (disk->data != last_devpath)
    {
      if (last_ihandle)
	grub_ieee1275_close (last_ihandle);
      last_ihandle = 0;
      last_devpath = NULL;

      if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
	{
	  char name2[grub_strlen (disk->data) + 3];
	  char *p;
	  
	  grub_strcpy (name2, disk->data);
	  p = name2 + grub_strlen (name2);
	  *p++ = ':';
	  *p++ = '0';
	  *p = 0;
	  grub_ieee1275_open (name2, &last_ihandle);
	}
      else
	grub_ieee1275_open (disk->data, &last_ihandle);
      if (! last_ihandle)
	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
      last_devpath = disk->data;      
    }

  pos = sector * 512UL;

  grub_ieee1275_seek (last_ihandle, pos, &status);
  if (status < 0)
    return grub_error (GRUB_ERR_READ_ERROR,
		       "seek error, can't seek block %llu",
		       (long long) sector);
  grub_ieee1275_read (last_ihandle, buf, size * 512UL, &actual);
  if (actual != (grub_ssize_t) (size * 512UL))
    return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
		       (long long) sector);

  return 0;
}
Пример #3
0
static grub_err_t
grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
{
  grub_ssize_t status;
  unsigned long long pos;

  if (disk->data != last_devpath)
    {
      if (last_ihandle)
	grub_ieee1275_close (last_ihandle);
      last_ihandle = 0;
      last_devpath = NULL;

      if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
	{
	  char name2[grub_strlen (disk->data) + 3];
	  char *p;
	  
	  grub_strcpy (name2, disk->data);
	  p = name2 + grub_strlen (name2);
	  *p++ = ':';
	  *p++ = '0';
	  *p = 0;
	  grub_ieee1275_open (name2, &last_ihandle);
	}
      else
	grub_ieee1275_open (disk->data, &last_ihandle);
      if (! last_ihandle)
	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
      last_devpath = disk->data;      
    }

  pos = sector << GRUB_DISK_SECTOR_BITS;

  grub_ieee1275_seek (last_ihandle, pos, &status);
  if (status < 0)
    return grub_error (GRUB_ERR_READ_ERROR,
		       "seek error, can't seek block %llu",
		       (long long) sector);
  return 0;
}
Пример #4
0
static grub_err_t
grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
		  grub_size_t size, char *buf)
{
  grub_ssize_t status, actual;
  unsigned long long pos;
  struct ofdisk_hash_ent *data = disk->data;

  pos = sector * 512UL;

  grub_ieee1275_seek (data->dev_ihandle, pos, &status);
  if (status < 0)
    return grub_error (GRUB_ERR_READ_ERROR,
		       "seek error, can't seek block %llu",
		       (long long) sector);
  size <<= 9;
  grub_ieee1275_read (data->dev_ihandle, buf, size, &actual);
  if (actual != (int) size)
    return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
		       (long long) sector);

  return 0;
}