* disk/ieee1275/ofdisk.c (struct ofdisk_hash_ent): New struct.
(OFDISK_HASH_SZ): Define. (ofdisk_hash): New hash table. (ofdisk_hash_fn, ofdisk_hash_find, ofdisk_hash_add): New functions. (grub_ofdisk_open): Use ofdisk_hash_ent address as disk->id instead of device phandle which is not unique.
This commit is contained in:
parent
e382e93a88
commit
f5dbbca97f
2 changed files with 68 additions and 9 deletions
|
@ -11,6 +11,13 @@
|
|||
* conf/i386-pc.rmk: Use *_FORMAT.
|
||||
* conf/i386-pc.mk: Rebuilt.
|
||||
|
||||
* disk/ieee1275/ofdisk.c (struct ofdisk_hash_ent): New struct.
|
||||
(OFDISK_HASH_SZ): Define.
|
||||
(ofdisk_hash): New hash table.
|
||||
(ofdisk_hash_fn, ofdisk_hash_find, ofdisk_hash_add): New functions.
|
||||
(grub_ofdisk_open): Use ofdisk_hash_ent address as disk->id
|
||||
instead of device phandle which is not unique.
|
||||
|
||||
2009-04-12 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* configure.ac: Change the logic when we check for target tools.
|
||||
|
|
|
@ -23,6 +23,53 @@
|
|||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/ieee1275/ofdisk.h>
|
||||
|
||||
struct ofdisk_hash_ent
|
||||
{
|
||||
char *devpath;
|
||||
struct ofdisk_hash_ent *next;
|
||||
};
|
||||
|
||||
#define OFDISK_HASH_SZ 8
|
||||
static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
|
||||
|
||||
static int
|
||||
ofdisk_hash_fn (const char *devpath)
|
||||
{
|
||||
int hash = 0;
|
||||
while (*devpath)
|
||||
hash ^= *devpath++;
|
||||
return (hash & (OFDISK_HASH_SZ - 1));
|
||||
}
|
||||
|
||||
static struct ofdisk_hash_ent *
|
||||
ofdisk_hash_find (const char *devpath)
|
||||
{
|
||||
struct ofdisk_hash_ent *p = ofdisk_hash[ofdisk_hash_fn(devpath)];
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (!grub_strcmp (p->devpath, devpath))
|
||||
break;
|
||||
p = p->next;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static struct ofdisk_hash_ent *
|
||||
ofdisk_hash_add (char *devpath)
|
||||
{
|
||||
struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
|
||||
struct ofdisk_hash_ent *p = grub_malloc(sizeof (*p));
|
||||
|
||||
if (p)
|
||||
{
|
||||
p->devpath = devpath;
|
||||
p->next = *head;
|
||||
*head = p;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_ofdisk_iterate (int (*hook) (const char *name))
|
||||
{
|
||||
|
@ -76,6 +123,7 @@ 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];
|
||||
|
@ -89,18 +137,26 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|||
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
|
||||
grub_strcat (devpath, ":0");
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
|
||||
op = ofdisk_hash_find (devpath);
|
||||
if (!op)
|
||||
op = ofdisk_hash_add (devpath);
|
||||
|
||||
grub_ieee1275_open (devpath, &dev_ihandle);
|
||||
grub_free (devpath);
|
||||
if (!op)
|
||||
return grub_errno;
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'.\n", op->devpath);
|
||||
|
||||
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", devpath, (void *) dev_ihandle);
|
||||
grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath, (void *) dev_ihandle);
|
||||
|
||||
if (grub_ieee1275_finddevice (devpath, &dev))
|
||||
if (grub_ieee1275_finddevice (op->devpath, &dev))
|
||||
{
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't read device properties");
|
||||
goto fail;
|
||||
|
@ -124,20 +180,16 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|||
is possible to use seek for this. */
|
||||
disk->total_sectors = 0xFFFFFFFFUL;
|
||||
|
||||
/* XXX: Is it ok to use this? Perhaps it is better to use the path
|
||||
or some property. */
|
||||
disk->id = dev;
|
||||
disk->id = (unsigned long) op;
|
||||
|
||||
/* XXX: Read this, somehow. */
|
||||
disk->has_partitions = 1;
|
||||
disk->data = (void *) dev_ihandle;
|
||||
grub_free (devpath);
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (dev_ihandle)
|
||||
grub_ieee1275_close (dev_ihandle);
|
||||
grub_free (devpath);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue