[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[2090] * disk/ieee1275/ofdisk.c (struct ofdisk_hash_ent): New struct.
From: |
David S. Miller |
Subject: |
[2090] * disk/ieee1275/ofdisk.c (struct ofdisk_hash_ent): New struct. |
Date: |
Mon, 13 Apr 2009 06:40:34 +0000 |
Revision: 2090
http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2090
Author: davem
Date: 2009-04-13 06:40:34 +0000 (Mon, 13 Apr 2009)
Log Message:
-----------
* 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.
Modified Paths:
--------------
trunk/grub2/ChangeLog
trunk/grub2/disk/ieee1275/ofdisk.c
Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog 2009-04-13 06:37:50 UTC (rev 2089)
+++ trunk/grub2/ChangeLog 2009-04-13 06:40:34 UTC (rev 2090)
@@ -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 <address@hidden>
* configure.ac: Change the logic when we check for target tools.
Modified: trunk/grub2/disk/ieee1275/ofdisk.c
===================================================================
--- trunk/grub2/disk/ieee1275/ofdisk.c 2009-04-13 06:37:50 UTC (rev 2089)
+++ trunk/grub2/disk/ieee1275/ofdisk.c 2009-04-13 06:40:34 UTC (rev 2090)
@@ -23,7 +23,54 @@
#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))
{
auto int dev_iterate (struct grub_ieee1275_devalias *alias);
@@ -76,6 +123,7 @@
{
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 @@
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 @@
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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [2090] * disk/ieee1275/ofdisk.c (struct ofdisk_hash_ent): New struct.,
David S. Miller <=