2009-09-10 Colin Watson
* disk/loopback.c (struct grub_loopback): Add `root' member.
(delete_loopback): Free `dev->root'.
(grub_cmd_loopback): Save the `root' environment variable.
(grub_loopback_open): Set the `root' environment variable
temporarily to that which was in effect when the `loopback' command
was run.
Index: disk/loopback.c
===================================================================
--- disk/loopback.c (revision 2584)
+++ disk/loopback.c (working copy)
@@ -23,10 +23,12 @@
#include
#include
#include
+#include
struct grub_loopback
{
char *devname;
+ char *root;
char *filename;
int has_partitions;
struct grub_loopback *next;
@@ -62,6 +64,7 @@
*prev = dev->next;
grub_free (dev->devname);
+ grub_free (dev->root);
grub_free (dev->filename);
grub_free (dev);
@@ -125,6 +128,13 @@
return grub_errno;
}
+ newdev->root = grub_strdup (grub_env_get ("root"));
+ if (! newdev->root)
+ {
+ grub_free (newdev);
+ return grub_errno;
+ }
+
newdev->filename = grub_strdup (args[1]);
if (! newdev->filename)
{
@@ -161,6 +171,7 @@
{
grub_file_t file;
struct grub_loopback *dev;
+ char *save_root;
for (dev = loopback_list; dev; dev = dev->next)
if (grub_strcmp (dev->devname, name) == 0)
@@ -169,9 +180,16 @@
if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't open device");
+ save_root = grub_strdup (grub_env_get ("root"));
+ grub_env_set ("root", dev->root);
+
file = grub_file_open (dev->filename);
if (! file)
- return grub_errno;
+ {
+ grub_env_set ("root", save_root);
+ grub_free (save_root);
+ return grub_errno;
+ }
/* Use the filesize for the disk size, round up to a complete sector. */
disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1)
@@ -181,6 +199,9 @@
disk->has_partitions = dev->has_partitions;
disk->data = file;
+ grub_env_set ("root", save_root);
+ grub_free (save_root);
+
return 0;
}