Use grub-probe and not cmp to check that disk is empty.

* util/grub-install.in: Use grub-probe for zero-check.
	* util/grub-probe.c (PRINT_ZERO_CHECK): New enum value.
	(probe): Handle PRINT_ZERO_CHECK.
	(argp_parser): Handle -t zero_check.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-05-11 21:07:39 +02:00
parent f1a6254cf1
commit fe8c2f1117
3 changed files with 53 additions and 2 deletions

View File

@ -1,4 +1,13 @@
2012-05-10 Vladimir Serbinenko <phcoder@gmail.com>
2012-05-11 Vladimir Serbinenko <phcoder@gmail.com>
Use grub-probe and not cmp to check that disk is empty.
* util/grub-install.in: Use grub-probe for zero-check.
* util/grub-probe.c (PRINT_ZERO_CHECK): New enum value.
(probe): Handle PRINT_ZERO_CHECK.
(argp_parser): Handle -t zero_check.
2012-05-11 Vladimir Serbinenko <phcoder@gmail.com>
Flush block cache on adding disk to device map.

View File

@ -776,7 +776,7 @@ elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ]
exit 1
fi
if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ $(cmp /dev/zero "${install_device}" &>/dev/null) ]; then
if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
# Change boot device to the harddisk root
boot_device="$ofpath"
dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {

View File

@ -67,6 +67,7 @@ enum {
PRINT_ARC_HINT,
PRINT_COMPATIBILITY_HINT,
PRINT_MSDOS_PARTTYPE,
PRINT_ZERO_CHECK,
PRINT_DISK
};
@ -392,6 +393,45 @@ probe (const char *path, char **device_names, char delim)
goto end;
}
if (print == PRINT_ZERO_CHECK)
{
for (curdev = drives_names; *curdev; curdev++)
{
grub_device_t dev = NULL;
grub_uint32_t buffer[32768];
grub_disk_addr_t addr;
grub_disk_addr_t dsize;
grub_util_info ("opening %s", *curdev);
dev = grub_device_open (*curdev);
if (! dev || !dev->disk)
grub_util_error ("%s", grub_errmsg);
dsize = grub_disk_get_size (dev->disk);
for (addr = 0; addr < dsize;
addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE)
{
grub_size_t sz = sizeof (buffer);
grub_uint32_t *ptr;
if (sizeof (buffer) / GRUB_DISK_SECTOR_SIZE > dsize - addr)
sz = (dsize - addr) * GRUB_DISK_SECTOR_SIZE;
grub_disk_read (dev->disk, addr, 0, sz, buffer);
for (ptr = buffer; ptr < buffer + sz / sizeof (*buffer); ptr++)
if (*ptr)
{
grub_printf ("false\n");
grub_device_close (dev);
goto end;
}
}
grub_device_close (dev);
}
grub_printf ("true\n");
}
if (print == PRINT_FS || print == PRINT_FS_UUID
|| print == PRINT_FS_LABEL)
{
@ -770,6 +810,8 @@ argp_parser (int key, char *arg, struct argp_state *state)
print = PRINT_ARC_HINT;
else if (!strcmp (arg, "compatibility_hint"))
print = PRINT_COMPATIBILITY_HINT;
else if (strcmp (arg, "zero_check") == 0)
print = PRINT_ZERO_CHECK;
else if (!strcmp (arg, "disk"))
print = PRINT_DISK;
else