Don't continue to query block-size if disk doesn't have it.

Stops poluting screen with a lot of "block-size: exception -21".
This commit is contained in:
Vladimir Serbinenko 2015-02-27 14:26:00 +01:00
parent 018f79da6f
commit 87ec3b7fa9
2 changed files with 44 additions and 21 deletions

View file

@ -35,6 +35,7 @@ struct ofdisk_hash_ent
char *grub_devpath;
int is_boot;
int is_removable;
int block_size_fails;
/* Pointer to shortest available name on nodes representing canonical names,
otherwise NULL. */
const char *shortest;
@ -42,6 +43,10 @@ struct ofdisk_hash_ent
struct ofdisk_hash_ent *next;
};
static grub_err_t
grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
struct ofdisk_hash_ent *op);
#define OFDISK_HASH_SZ 8
static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
@ -375,6 +380,8 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
/* XXX: This should be large enough for any possible case. */
char prop[64];
grub_ssize_t actual;
grub_uint32_t block_size = 0;
grub_err_t err;
if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
@ -405,14 +412,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
}
grub_uint32_t block_size = 0;
if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
{
for (disk->log_sector_size = 0;
(1U << disk->log_sector_size) < block_size;
disk->log_sector_size++);
}
/* XXX: There is no property to read the number of blocks. There
should be a property `#blocks', but it is not there. Perhaps it
is possible to use seek for this. */
@ -429,6 +428,18 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
return grub_errno;
disk->id = (unsigned long) op;
disk->data = op->open_path;
err = grub_ofdisk_get_block_size (devpath, &block_size, op);
if (err)
return err;
if (block_size != 0)
{
for (disk->log_sector_size = 0;
(1U << disk->log_sector_size) < block_size;
disk->log_sector_size++);
}
else
disk->log_sector_size = 9;
}
return 0;
@ -589,8 +600,9 @@ grub_ofdisk_init (void)
grub_disk_dev_register (&grub_ofdisk_dev);
}
grub_err_t
grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
static grub_err_t
grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
struct ofdisk_hash_ent *op)
{
struct size_args_ieee1275
{
@ -612,20 +624,34 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
if (! last_ihandle)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
*block_size = 0;
if (op->block_size_fails >= 2)
return GRUB_ERR_NONE;
INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
args_ieee1275.ihandle = last_ihandle;
args_ieee1275.result = 1;
*block_size = GRUB_DISK_SECTOR_SIZE;
if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
grub_dprintf ("disk", "can't get block size\n");
else
if (args_ieee1275.size1
if (IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1)
{
grub_dprintf ("disk", "can't get block size: failed call-method\n");
op->block_size_fails++;
}
else if (args_ieee1275.result)
{
grub_dprintf ("disk", "can't get block size: %lld\n",
(long long) args_ieee1275.result);
op->block_size_fails++;
}
else if (args_ieee1275.size1
&& !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
&& args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
{
op->block_size_fails = 0;
*block_size = args_ieee1275.size1;
}
return 0;
}

View file

@ -22,7 +22,4 @@
extern void grub_ofdisk_init (void);
extern void grub_ofdisk_fini (void);
extern grub_err_t grub_ofdisk_get_block_size (const char *device,
grub_uint32_t *block_size);
#endif /* ! GRUB_INIT_HEADER */