disk: Allow read hook callback to take read buffer to potentially modify it

It will be desirable in the future to allow having the read hook modify the
data passed back from a read function call on a disk or file. This adds that
infrastructure and has no impact on code flow for existing uses of the read
hook. Also changed is that now when the read hook callback is called it can
also indicate what error code should be sent back to the read caller.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn authored and Daniel Kiper committed 2022-07-04 14:43:25 +02:00
1 parent 190d79e135
commit f5a92e6040
9 files changed
+40 -31

No files matched your search

+6 -4
View File
@@ -53,9 +53,9 @@ print_blocklist (grub_disk_addr_t sector, unsigned num,
}
/* Helper for grub_cmd_blocklist. */
static void
static grub_err_t
read_blocklist (grub_disk_addr_t sector, unsigned offset, unsigned length,
void *data)
char *buf __attribute__ ((unused)), void *data)
{
struct blocklist_ctx *ctx = data;
@@ -70,7 +70,7 @@ read_blocklist (grub_disk_addr_t sector, unsigned offset, unsigned length,
}
if (!length)
return;
return GRUB_ERR_NONE;
print_blocklist (ctx->start_sector, ctx->num_sectors, 0, 0, ctx);
ctx->num_sectors = 0;
}
@@ -87,7 +87,7 @@ read_blocklist (grub_disk_addr_t sector, unsigned offset, unsigned length,
}
if (!length)
return;
return GRUB_ERR_NONE;
if (length & (GRUB_DISK_SECTOR_SIZE - 1))
{
@@ -103,6 +103,8 @@ read_blocklist (grub_disk_addr_t sector, unsigned offset, unsigned length,
ctx->start_sector = sector;
ctx->num_sectors = length >> GRUB_DISK_SECTOR_BITS;
}
return GRUB_ERR_NONE;
}
static grub_err_t
+5 -3
View File
@@ -352,16 +352,16 @@ struct grub_cmd_save_env_ctx
};
/* Store blocklists in a linked list. */
static void
static grub_err_t
save_env_read_hook (grub_disk_addr_t sector, unsigned offset, unsigned length,
void *data)
char *buf __attribute__ ((unused)), void *data)
{
struct grub_cmd_save_env_ctx *ctx = data;
struct blocklist *block;
block = grub_malloc (sizeof (*block));
if (! block)
return;
return GRUB_ERR_NONE;
block->sector = sector;
block->offset = offset;
@@ -374,6 +374,8 @@ save_env_read_hook (grub_disk_addr_t sector, unsigned offset, unsigned length,
ctx->tail = block;
if (! ctx->head)
ctx->head = block;
return GRUB_ERR_NONE;
}
static grub_err_t
+3 -1
View File
@@ -32,10 +32,11 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* Helper for grub_cmd_testload. */
static void
static grub_err_t
read_progress (grub_disk_addr_t sector __attribute__ ((unused)),
unsigned offset __attribute__ ((unused)),
unsigned len,
char *buf __attribute__ ((unused)),
void *data __attribute__ ((unused)))
{
for (; len >= GRUB_DISK_SECTOR_SIZE; len -= GRUB_DISK_SECTOR_SIZE)
@@ -43,6 +44,7 @@ read_progress (grub_disk_addr_t sector __attribute__ ((unused)),
if (len)
grub_xputs (".");
grub_refresh ();
return GRUB_ERR_NONE;
}
static grub_err_t