From e8ed2571c4215ac8cbc56b8524d6d363485c8c1f Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 24 Aug 2023 09:33:47 +0200 Subject: [PATCH 04/14] Fix compilation of generic/blocklist After recent change in blocklist types we have a type mismatch. Fixing it requires a wrapper or large changes. I feel like wrapper makes more sense Without this patch we end up with a compilation problem and without wrapping callback data is not passed properly anymore Signed-off-by: Vladimir Serbinenko --- grub-core/osdep/generic/blocklist.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/grub-core/osdep/generic/blocklist.c b/grub-core/osdep/generic/blocklist.c index 2d9040302..97e416866 100644 --- a/grub-core/osdep/generic/blocklist.c +++ b/grub-core/osdep/generic/blocklist.c @@ -30,6 +30,25 @@ #define MAX_TRIES 5 +struct wrapper_hook_data +{ + void (*callback) (grub_disk_addr_t sector, + unsigned offset, + unsigned length, + void *data); + void *callback_data; +}; + +static grub_err_t +callback_wrapper (grub_disk_addr_t sector, + unsigned offset, unsigned length, + char *buf, void *data) +{ + struct wrapper_hook_data *wrap = data; + wrap->callback(sector, offset, length, wrap->callback_data); + return GRUB_ERR_NONE; +} + void grub_install_get_blocklist (grub_device_t root_dev, const char *core_path, const char *core_img, @@ -43,6 +62,10 @@ grub_install_get_blocklist (grub_device_t root_dev, int i; char *tmp_img; char *core_path_dev; + struct wrapper_hook_data wrap_hook_data = { + .callback = callback, + .callback_data = hook_data + }; core_path_dev = grub_make_system_path_relative_to_its_root (core_path); @@ -120,8 +143,8 @@ grub_install_get_blocklist (grub_device_t root_dev, if (! file) grub_util_error ("%s", grub_errmsg); - file->read_hook = callback; - file->read_hook_data = hook_data; + file->read_hook = callback_wrapper; + file->read_hook_data = &wrap_hook_data; if (grub_file_read (file, tmp_img, core_size) != (grub_ssize_t) core_size) grub_util_error ("%s", _("failed to read the sectors of the core image")); -- 2.39.2