grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] bufio: fix the next_buf calculation


From: Daniel Kiper
Subject: Re: [PATCH] bufio: fix the next_buf calculation
Date: Tue, 17 Apr 2018 19:11:34 +0200
User-agent: Mutt/1.3.28i

CC-ing Vladimir.

On Mon, Apr 16, 2018 at 06:05:04PM +0800, Michael Chang wrote:
> The next_buf is the offset to the next cached block rounded to the size of
> bufio->block_size. However the calculation needs the block_size to be in power
> of 2 is not always valid. As an example, files with smaller size than
> block_size will have the block_size leveled to the size of file which can be
> set arbitrary value.
>
> This patch fixes the next_buf calculation to accept any integers.
>
> Signed-off-by: Michael Chang <address@hidden>
> ---
>  grub-core/io/bufio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c
> index 22438277d..d0b0f71b6 100644
> --- a/grub-core/io/bufio.c
> +++ b/grub-core/io/bufio.c
> @@ -132,7 +132,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t 
> len)
>      return res;
>
>    /* Need to read some more.  */
> -  next_buf = (file->offset + res + len - 1) & ~((grub_off_t) 
> bufio->block_size - 1);
> +  next_buf = (grub_divmod64 (file->offset + res + len - 1, 
> bufio->block_size, NULL)) * bufio->block_size;

Should not you fix this in grub_bufio_open()? I think that
you should look for closest power of 2 in it.

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]