* include/grub/disk.h (grub_disk): Remove has_partitions.

All users updated.
	* disk/loopback.c (grub_loopback): Remove has_partitions.
	All users updated.
	(options): Remove partitions. All users updated.
	* util/grub-fstest.c (fstest): Don't pass "-p" to loopback.
	* util/i386/pc/grub-setup.c (setup): copy partition table only when
	actual partition table is found.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-13 23:59:22 +02:00
parent 3352800b99
commit 94564f81a8
21 changed files with 49 additions and 71 deletions

View File

@ -1,3 +1,14 @@
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/disk.h (grub_disk): Remove has_partitions.
All users updated.
* disk/loopback.c (grub_loopback): Remove has_partitions.
All users updated.
(options): Remove partitions. All users updated.
* util/grub-fstest.c (fstest): Don't pass "-p" to loopback.
* util/i386/pc/grub-setup.c (setup): copy partition table only when
actual partition table is found.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Remove readability checks (too many false negatives).

View File

@ -723,7 +723,6 @@ grub_ata_open (const char *name, grub_disk_t disk)
disk->id = (unsigned long) dev;
disk->has_partitions = 1;
disk->data = dev;
return 0;

View File

@ -514,16 +514,12 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
switch (name[0])
{
case 'f':
disk->has_partitions = 0;
d = get_device (fd_devices, num);
break;
case 'c':
/* FIXME: a CDROM should have partitions, but not implemented yet. */
disk->has_partitions = 0;
d = get_device (cd_devices, num);
break;
case 'h':
disk->has_partitions = 1;
d = get_device (hd_devices, num);
break;
default:

View File

@ -43,7 +43,6 @@ grub_host_open (const char *name, grub_disk_t disk)
disk->total_sectors = 0;
disk->id = (unsigned long) "host";
disk->has_partitions = 0;
disk->data = 0;
return GRUB_ERR_NONE;

View File

@ -327,7 +327,6 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
if (drive < 0)
return grub_errno;
disk->has_partitions = 1;
disk->id = drive;
data = (struct grub_biosdisk_data *) grub_zalloc (sizeof (*data));

View File

@ -113,7 +113,6 @@ grub_nand_open (const char *name, grub_disk_t disk)
disk->id = dev_ihandle;
disk->has_partitions = 0;
disk->data = data;
return 0;

View File

@ -256,8 +256,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
disk->data = op->devpath;
}
/* XXX: Read this, somehow. */
disk->has_partitions = 1;
return 0;
}

View File

@ -29,7 +29,6 @@ struct grub_loopback
{
char *devname;
grub_file_t file;
int has_partitions;
struct grub_loopback *next;
};
@ -38,7 +37,6 @@ static struct grub_loopback *loopback_list;
static const struct grub_arg_option options[] =
{
{"delete", 'd', 0, N_("Delete the loopback device entry."), 0, 0},
{"partitions", 'p', 0, N_("Simulate a hard drive with partitions."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
@ -106,9 +104,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
grub_file_close (newdev->file);
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
return 0;
}
@ -126,9 +121,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
/* Add the new entry to the list. */
newdev->next = loopback_list;
loopback_list = newdev;
@ -174,7 +166,6 @@ grub_loopback_open (const char *name, grub_disk_t disk)
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions;
disk->data = dev->file;
return 0;

View File

@ -150,7 +150,6 @@ grub_lvm_open (const char *name, grub_disk_t disk)
if (! lv)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown LVM device %s", name);
disk->has_partitions = 0;
disk->id = lv->number;
disk->data = lv;
disk->total_sectors = lv->size;
@ -280,7 +279,11 @@ grub_lvm_scan_device (const char *name)
disk = grub_disk_open (name);
if (!disk)
return 0;
{
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_errno = GRUB_ERR_NONE;
return 0;
}
/* Search for label. */
for (i = 0; i < GRUB_LVM_LABEL_SCAN_SECTORS; i++)
@ -725,6 +728,8 @@ grub_lvm_scan_device (const char *name)
grub_free (metadatabuf);
fail:
grub_disk_close (disk);
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_errno = GRUB_ERR_NONE;
return 0;
}

View File

@ -41,7 +41,6 @@ grub_memdisk_open (const char *name, grub_disk_t disk)
disk->total_sectors = memdisk_size / GRUB_DISK_SECTOR_SIZE;
disk->id = (unsigned long) "mdsk";
disk->has_partitions = 0;
return GRUB_ERR_NONE;
}

View File

@ -126,7 +126,6 @@ grub_raid_open (const char *name, grub_disk_t disk)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s",
name);
disk->has_partitions = 1;
disk->id = array->number;
disk->data = array;

View File

@ -431,12 +431,6 @@ grub_scsi_open (const char *name, grub_disk_t disk)
"unknown SCSI device");
}
if (scsi->devtype == grub_scsi_devtype_cdrom)
disk->has_partitions = 0;
else
disk->has_partitions = 1;
/* According to USB MS tests specification, issue Test Unit Ready
* until OK */
maxtime = grub_get_time_ms () + 5000; /* It is safer value */

View File

@ -176,7 +176,6 @@ grub_pxe_open (const char *name, grub_disk_t disk)
disk->total_sectors = 0;
disk->id = (unsigned long) data;
disk->has_partitions = 0;
disk->data = data;
return GRUB_ERR_NONE;

View File

@ -103,7 +103,7 @@ grub_device_iterate (int (*hook) (const char *name))
return 0;
}
if (dev->disk && dev->disk->has_partitions)
if (dev->disk)
{
struct part_ent *p;
int ret = 0;

View File

@ -281,12 +281,6 @@ grub_disk_open (const char *name)
goto fail;
}
if (p && ! disk->has_partitions)
{
grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk");
goto fail;
}
disk->dev = dev;
if (p)

View File

@ -221,7 +221,6 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"no mapping exists for `%s'", name);
disk->has_partitions = 1;
disk->id = drive;
disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data));
data->dev = NULL;

View File

@ -160,14 +160,23 @@ iterate_dev (const char *devname)
if (dev)
{
if (dev->disk && dev->disk->has_partitions)
char tmp[grub_strlen (devname) + sizeof (",")];
grub_memcpy (tmp, devname, grub_strlen (devname));
if (grub_strcmp (devname, current_word) == 0)
{
if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE))
if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_PARTITION))
return 1;
if (dev->disk)
if (grub_partition_iterate (dev->disk, iterate_partition))
return 1;
}
else
{
if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE))
grub_memcpy (tmp + grub_strlen (devname), "", sizeof (""));
if (add_completion (tmp, "", GRUB_COMPLETION_TYPE_DEVICE))
return 1;
}
}
@ -200,7 +209,7 @@ complete_device (void)
if (dev)
{
if (dev->disk && dev->disk->has_partitions)
if (dev->disk)
{
if (grub_partition_iterate (dev->disk, iterate_partition))
{

View File

@ -108,10 +108,8 @@ grub_normal_print_device_info (const char *name)
grub_errno = GRUB_ERR_NONE;
}
}
else if (! dev->disk->has_partitions || dev->disk->partition)
grub_printf ("%s", _("Unknown filesystem"));
else
grub_printf ("%s", _("Partition table"));
grub_printf ("%s", _("Not a known filesystem"));
if (dev->disk->partition)
grub_printf (_(" - Partition start at %u"),

View File

@ -99,9 +99,6 @@ struct grub_disk
/* The total number of sectors. */
grub_uint64_t total_sectors;
/* If partitions can be stored. */
int has_partitions;
/* The id used by the disk cache manager. */
unsigned long id;

View File

@ -259,13 +259,11 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
{
char *host_file;
char *loop_name;
char *argv[3];
int i;
argv[0] = "-p";
for (i = 0; i < num_disks; i++)
{
char *argv[2];
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
@ -274,10 +272,10 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
if (!host_file)
grub_util_error (grub_errmsg);
argv[1] = loop_name;
argv[2] = host_file;
argv[0] = loop_name;
argv[1] = host_file;
if (execute_command ("loopback", 3, argv))
if (execute_command ("loopback", 2, argv))
grub_util_error ("loopback command fails");
grub_free (loop_name);
@ -312,15 +310,16 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
execute_command ("blocklist", n, args);
grub_printf ("\n");
}
argv[0] = "-d";
for (i = 0; i < num_disks; i++)
{
char *argv[2];
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
argv[0] = "-d";
argv[1] = loop_name;
execute_command ("loopback", 2, argv);

View File

@ -252,14 +252,6 @@ setup (const char *dir,
tmp_img + GRUB_BOOT_MACHINE_BPB_START,
GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
/* Copy the possible partition table. */
if (dest_dev->disk->has_partitions)
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
for buggy BIOSes which don't pass boot drive correctly. Instead,
they pass 0x00 or 0x01 even when booted from 0x80. */
@ -300,12 +292,6 @@ setup (const char *dir,
grub_util_info ("dos partition is %d, bsd partition is %d",
dos_part, bsd_part);
if (! dest_dev->disk->has_partitions)
{
grub_util_warn (_("Attempting to install GRUB to a partitionless disk. This is a BAD idea."));
goto unable_to_embed;
}
if (dest_dev->disk->partition)
{
grub_util_warn (_("Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea."));
@ -345,6 +331,14 @@ setup (const char *dir,
goto unable_to_embed;
}
/* Copy the partition table. */
if (dest_partmap)
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
if (strcmp (dest_partmap, "msdos") == 0)
grub_partition_iterate (dest_dev->disk, find_usable_region_msdos);
else if (strcmp (dest_partmap, "gpt") == 0)