Avoiding openning same device multiple times in device iterator.
* kern/device.c (grub_device_iterate): Define struct part_ent, and use it to build a list of partitions in interate_disk() and iterate_partition().
This commit is contained in:
parent
c8c08833e3
commit
0d31250038
2 changed files with 51 additions and 15 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2009-04-24 David S. Miller <davem@davemloft.net>
|
||||||
|
|
||||||
|
Avoiding openning same device multiple times in device iterator.
|
||||||
|
|
||||||
|
* kern/device.c: (grub_device_iterate): Define struct part_ent,
|
||||||
|
and use it to build a list of partitions in interate_disk() and
|
||||||
|
iterate_partition().
|
||||||
|
|
||||||
2009-04-23 David S. Miller <davem@davemloft.net>
|
2009-04-23 David S. Miller <davem@davemloft.net>
|
||||||
|
|
||||||
* kern/sparc64/ieee1275/openfw.c: Unused, delete.
|
* kern/sparc64/ieee1275/openfw.c: Unused, delete.
|
||||||
|
|
|
@ -83,6 +83,12 @@ grub_device_iterate (int (*hook) (const char *name))
|
||||||
auto int iterate_partition (grub_disk_t disk,
|
auto int iterate_partition (grub_disk_t disk,
|
||||||
const grub_partition_t partition);
|
const grub_partition_t partition);
|
||||||
|
|
||||||
|
struct part_ent
|
||||||
|
{
|
||||||
|
struct part_ent *next;
|
||||||
|
char *name;
|
||||||
|
} *ents = NULL;
|
||||||
|
|
||||||
int iterate_disk (const char *disk_name)
|
int iterate_disk (const char *disk_name)
|
||||||
{
|
{
|
||||||
grub_device_t dev;
|
grub_device_t dev;
|
||||||
|
@ -95,11 +101,28 @@ grub_device_iterate (int (*hook) (const char *name))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (dev->disk && dev->disk->has_partitions)
|
if (dev->disk && dev->disk->has_partitions)
|
||||||
if (grub_partition_iterate (dev->disk, iterate_partition))
|
{
|
||||||
{
|
struct part_ent *p;
|
||||||
grub_device_close (dev);
|
int ret = 0;
|
||||||
return 1;
|
|
||||||
}
|
(void) grub_partition_iterate (dev->disk, iterate_partition);
|
||||||
|
grub_device_close (dev);
|
||||||
|
|
||||||
|
p = ents;
|
||||||
|
ents = NULL;
|
||||||
|
while (p != NULL)
|
||||||
|
{
|
||||||
|
struct part_ent *next = p->next;
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
ret = hook (p->name);
|
||||||
|
grub_free (p->name);
|
||||||
|
grub_free (p);
|
||||||
|
p = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
grub_device_close (dev);
|
grub_device_close (dev);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -108,27 +131,32 @@ grub_device_iterate (int (*hook) (const char *name))
|
||||||
int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
|
int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
|
||||||
{
|
{
|
||||||
char *partition_name;
|
char *partition_name;
|
||||||
char *device_name;
|
struct part_ent *p;
|
||||||
int ret;
|
|
||||||
|
|
||||||
partition_name = grub_partition_get_name (partition);
|
partition_name = grub_partition_get_name (partition);
|
||||||
if (! partition_name)
|
if (! partition_name)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
device_name = grub_malloc (grub_strlen (disk->name) + 1
|
p = grub_malloc (sizeof (*p));
|
||||||
+ grub_strlen (partition_name) + 1);
|
if (!p)
|
||||||
if (! device_name)
|
return 1;
|
||||||
|
|
||||||
|
p->name = grub_malloc (grub_strlen (disk->name) + 1
|
||||||
|
+ grub_strlen (partition_name) + 1);
|
||||||
|
if (! p->name)
|
||||||
{
|
{
|
||||||
|
grub_free (p);
|
||||||
grub_free (partition_name);
|
grub_free (partition_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_sprintf (device_name, "%s,%s", disk->name, partition_name);
|
grub_sprintf (p->name, "%s,%s", disk->name, partition_name);
|
||||||
grub_free (partition_name);
|
grub_free (partition_name);
|
||||||
|
|
||||||
ret = hook (device_name);
|
p->next = ents;
|
||||||
grub_free (device_name);
|
ents = p;
|
||||||
return ret;
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only disk devices are supported at the moment. */
|
/* Only disk devices are supported at the moment. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue