@@ -457,6 +457,13 @@ get_device (struct grub_efidisk_data *devices, int num)
return 0;
}
+static void *
+aligned_malloc (struct grub_disk *disk, grub_size_t size)
+{
+ struct grub_efidisk_data *d = disk->data;
+ return grub_memalign (d->block_io->media->io_align, size);
+}
+
static grub_err_t
grub_efidisk_open (const char *name, struct grub_disk *disk)
{
@@ -493,8 +500,15 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
m = d->block_io->media;
/* FIXME: Probably it is better to store the block size in the disk,
and total sectors should be replaced with total blocks. */
- grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n",
- m, (unsigned long long) m->last_block, m->block_size);
+ grub_dprintf ("efidisk",
+ "m = %p, last block = %llx, block size = %x, io align = %x\n",
+ m, (unsigned long long) m->last_block, m->block_size,
+ m->io_align);
+
+ /* Ensure required buffer alignment is a power of two (or is zero). */
+ if (m->io_align & (m->io_align - 1))
+ return grub_error (GRUB_ERR_IO, "invalid buffer alignment %d", m->io_align);
+
disk->total_sectors = m->last_block + 1;
/* Don't increase this value due to bug in some EFI. */
disk->max_agglomerate = 0xa0000 >> (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS);
@@ -505,6 +519,7 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
(1U << disk->log_sector_size) < m->block_size;
disk->log_sector_size++);
disk->data = d;
+ disk->malloc = aligned_malloc;
grub_dprintf ("efidisk", "opening %s succeeded\n", name);