merge with mainline

This commit is contained in:
BVK Chaitanya 2010-08-19 16:54:00 +05:30
commit 16c7cb32c8
80 changed files with 5101 additions and 1687 deletions

View file

@ -28,7 +28,7 @@
struct grub_loopback
{
char *devname;
char *filename;
grub_file_t file;
int has_partitions;
struct grub_loopback *next;
};
@ -63,7 +63,7 @@ delete_loopback (const char *name)
*prev = dev->next;
grub_free (dev->devname);
grub_free (dev->filename);
grub_file_close (dev->file);
grub_free (dev);
return 0;
@ -76,6 +76,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
struct grub_arg_list *state = state = cmd->state;
grub_file_t file;
struct grub_loopback *newdev;
grub_err_t ret;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
@ -91,9 +92,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
if (! file)
return grub_errno;
/* Close the file, the only reason for opening it is validation. */
grub_file_close (file);
/* First try to replace the old device. */
for (newdev = loopback_list; newdev; newdev = newdev->next)
if (grub_strcmp (newdev->devname, args[0]) == 0)
@ -103,10 +101,10 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
{
char *newname = grub_strdup (args[1]);
if (! newname)
return grub_errno;
goto fail;
grub_free (newdev->filename);
newdev->filename = newname;
grub_file_close (newdev->file);
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
@ -117,22 +115,16 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
/* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev)
return grub_errno;
goto fail;
newdev->devname = grub_strdup (args[0]);
if (! newdev->devname)
{
grub_free (newdev);
return grub_errno;
goto fail;
}
newdev->filename = grub_strdup (args[1]);
if (! newdev->filename)
{
grub_free (newdev->devname);
grub_free (newdev);
return grub_errno;
}
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
@ -142,6 +134,11 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
loopback_list = newdev;
return 0;
fail:
ret = grub_errno;
grub_file_close (file);
return ret;
}
@ -160,7 +157,6 @@ grub_loopback_iterate (int (*hook) (const char *name))
static grub_err_t
grub_loopback_open (const char *name, grub_disk_t disk)
{
grub_file_t file;
struct grub_loopback *dev;
for (dev = loopback_list; dev; dev = dev->next)
@ -170,29 +166,17 @@ grub_loopback_open (const char *name, grub_disk_t disk)
if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
file = grub_file_open (dev->filename);
if (! file)
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)
disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1)
/ GRUB_DISK_SECTOR_SIZE);
disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions;
disk->data = file;
disk->data = dev->file;
return 0;
}
static void
grub_loopback_close (grub_disk_t disk)
{
grub_file_t file = (grub_file_t) disk->data;
grub_file_close (file);
}
static grub_err_t
grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf)
@ -234,7 +218,6 @@ static struct grub_disk_dev grub_loopback_dev =
.id = GRUB_DISK_DEVICE_LOOPBACK_ID,
.iterate = grub_loopback_iterate,
.open = grub_loopback_open,
.close = grub_loopback_close,
.read = grub_loopback_read,
.write = grub_loopback_write,
.next = 0