Received: from list by lists.gnu.org with archive (Exim 4.71) id 1f8jBJ-0000Jw-Bb for mharc-grub-devel@gnu.org; Wed, 18 Apr 2018 05:15:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8jBG-0000GI-FU for grub-devel@gnu.org; Wed, 18 Apr 2018 05:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8jBD-0004Aj-AL for grub-devel@gnu.org; Wed, 18 Apr 2018 05:15:10 -0400 Received: from boksu.net-space.pl ([185.15.1.105]:52511) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.71) (envelope-from ) id 1f8jBC-00049s-Uf for grub-devel@gnu.org; Wed, 18 Apr 2018 05:15:07 -0400 Received: (from localhost user: 'dkiper' uid#4000 fake: STDIN (dkiper@boksu.net-space.pl)) by router-fw-old.local.net-space.pl id S1836513AbeDRJPB (ORCPT ); Wed, 18 Apr 2018 11:15:01 +0200 Date: Wed, 18 Apr 2018 11:15:01 +0200 From: Daniel Kiper To: mchang@suse.com Cc: dkiper@net-space.pl, grub-devel@gnu.org, phcoder@gmail.com Subject: Re: [PATCH] bufio: fix the next_buf calculation Message-ID: <20180418091501.GA15091@router-fw-old.local.net-space.pl> References: <20180416100504.kbidvkerpritgigi@mazu> <20180417171134.GD21283@router-fw-old.local.net-space.pl> <20180418072820.tedbk7224yaec3fn@mazu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180418072820.tedbk7224yaec3fn@mazu> User-Agent: Mutt/1.3.28i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 185.15.1.105 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2018 09:15:11 -0000 On Wed, Apr 18, 2018 at 03:28:20PM +0800, Michael Chang wrote: > On Tue, Apr 17, 2018 at 07:11:34PM +0200, Daniel Kiper wrote: > > 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 > > > --- > > > 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. > > Of course here we can round up or down the bufio->block_size to meet power of > 2. The down side of round-down is inefficient for small files as it can't cache > entire file in one go. The round-up will have to allocate (slightly) larger > than needed buffer to hold small files which is not a big deal ... > > If you insist, I can work a new patch to round up the block_size in > grub_bufio_open, just let me know. Please do. Daniel