@@ -184,6 +184,15 @@ find_part_sep (const char *name)
return NULL;
}
+static void *
+disk_malloc (struct grub_disk *disk, grub_size_t size)
+{
+ if (disk->malloc)
+ return disk->malloc (disk, size);
+
+ return grub_malloc (size);
+}
+
grub_disk_t
grub_disk_open (const char *name)
{
@@ -331,7 +340,7 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
}
/* Allocate a temporary buffer. */
- tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ tmp_buf = disk_malloc (disk, GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
if (! tmp_buf)
return grub_errno;
@@ -373,7 +382,7 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
num = ((size + offset + (1ULL << (disk->log_sector_size))
- 1) >> (disk->log_sector_size));
- tmp_buf = grub_malloc (num << disk->log_sector_size);
+ tmp_buf = disk_malloc (disk, num << disk->log_sector_size);
if (!tmp_buf)
return grub_errno;
@@ -111,6 +111,8 @@ typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector,
unsigned offset, unsigned length,
void *data);
+typedef void *(*grub_disk_malloc_t) (struct grub_disk *disk, grub_size_t size);
+
/* Disk. */
struct grub_disk
{
@@ -144,6 +146,9 @@ struct grub_disk
/* Device-specific data. */
void *data;
+
+ /* Device-specific malloc function. */
+ grub_disk_malloc_t malloc;
};
typedef struct grub_disk *grub_disk_t;