From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vgehy-0002ZV-Ho for mharc-grub-devel@gnu.org; Wed, 13 Nov 2013 12:58:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgehr-0002ZF-74 for grub-devel@gnu.org; Wed, 13 Nov 2013 12:58:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vgehl-00021E-KM for grub-devel@gnu.org; Wed, 13 Nov 2013 12:58:23 -0500 Received: from mail-ea0-x22d.google.com ([2a00:1450:4013:c01::22d]:57052) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgehl-000217-9p for grub-devel@gnu.org; Wed, 13 Nov 2013 12:58:17 -0500 Received: by mail-ea0-f173.google.com with SMTP id g10so430319eak.4 for ; Wed, 13 Nov 2013 09:58:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=bJUjq9rZB1ALvGm3YLyOzZ09fPozIvjMkrUj+mXM2Lw=; b=Xzlw3Ydr1R8xieaTTXBzTzG5YB82TxHXRTgZiLKQ5b0QlWT23lKvZxgjDN+SCUQd6w ZpqlkqwfQs+DyhNRHeAH2ta2NATgUIvx3pIg8v8SMGtWDDWmJvYSf1QJVj9VuZoWE1I2 WHrVK/P6p9r0/MYdc/J5rb2WvPeAKcKvFQii5aQvU2WpvwYFu+P19lXlsK/lLjfZCdvI tICLTPQxb6fImE9VwYkkUcc1kU6unlNBlnbOGg2J9744zUzhz2DE+VFokBYa2LqoaDUw LXzHqFA/OnbFWDDgrh8FqJg9pEqaMmWTJmE3M+HMtM6FiiF/IKFopDpvaFV8qCOc8WF8 ObLA== X-Received: by 10.14.45.70 with SMTP id o46mr50422913eeb.19.1384365496336; Wed, 13 Nov 2013 09:58:16 -0800 (PST) Received: from [192.168.1.16] (31-249.1-85.cust.bluewin.ch. [85.1.249.31]) by mx.google.com with ESMTPSA id a51sm51835181eeh.8.2013.11.13.09.58.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Nov 2013 09:58:15 -0800 (PST) Message-ID: <5283BDB6.10709@gmail.com> Date: Wed, 13 Nov 2013 18:58:14 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] * grub-core/fs/ext2.c (grub_ext2_read_block): Factor out common code for indirect block handling. References: <20131113113352.GK16147@riva.ucam.org> In-Reply-To: <20131113113352.GK16147@riva.ucam.org> X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="----enig2IOFCDIPUDOIFOMFFEJFD" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22d X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Nov 2013 17:58:29 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2IOFCDIPUDOIFOMFFEJFD Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 13.11.2013 12:33, Colin Watson wrote: > Saves 185 bytes on compressed image. Go ahead. > --- > ChangeLog | 7 ++++ > grub-core/fs/ext2.c | 119 +++++++++++++++++---------------------------= -------- > 2 files changed, 45 insertions(+), 81 deletions(-) >=20 > diff --git a/ChangeLog b/ChangeLog > index 716f69c..4454fd8 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,5 +1,12 @@ > 2013-11-13 Colin Watson > =20 > + * grub-core/fs/ext2.c (grub_ext2_read_block): Factor out common > + code for indirect block handling. > + > + Saves 185 bytes on compressed image. > + > +2013-11-13 Colin Watson > + > * util/grub-editenv.c (help_filter, argp): Document how to delete > the whole environment block. > Reported by Dan Jacobson. Fixes Debian bug #726265. > diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c > index aba5cb1..5f7a2b9 100644 > --- a/grub-core/fs/ext2.c > +++ b/grub-core/fs/ext2.c > @@ -397,9 +397,12 @@ grub_ext2_read_block (grub_fshelp_node_t node, gru= b_disk_addr_t fileblock) > { > struct grub_ext2_data *data =3D node->data; > struct grub_ext2_inode *inode =3D &node->inode; > - grub_disk_addr_t blknr =3D -1; > unsigned int blksz =3D EXT2_BLOCK_SIZE (data); > + grub_disk_addr_t blksz_quarter =3D blksz / 4; > int log2_blksz =3D LOG2_EXT2_BLOCK_SIZE (data); > + int log_perblock =3D log2_blksz + 9 - 2; > + grub_uint32_t indir; > + int shift; > =20 > if (inode->flags & grub_cpu_to_le32_compile_time (EXT4_EXTENTS_FLAG)= ) > { > @@ -448,96 +451,50 @@ grub_ext2_read_block (grub_fshelp_node_t node, gr= ub_disk_addr_t fileblock) > =20 > return ret; > } > + > /* Direct blocks. */ > if (fileblock < INDIRECT_BLOCKS) > - blknr =3D grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]); > + return grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]); > + fileblock -=3D INDIRECT_BLOCKS; > /* Indirect. */ > - else if (fileblock < INDIRECT_BLOCKS + blksz / 4) > + if (fileblock < blksz_quarter) > { > - grub_uint32_t indir; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (inode->blocks.indir_block)) > - << log2_blksz, > - (fileblock - INDIRECT_BLOCKS) * sizeof (indir), > - sizeof (indir), &indir)) > - return grub_errno; > - > - blknr =3D grub_le_to_cpu32 (indir); > + indir =3D inode->blocks.indir_block; > + shift =3D 0; > + goto indirect; > } > + fileblock -=3D blksz_quarter; > /* Double indirect. */ > - else if (fileblock < INDIRECT_BLOCKS > - + blksz / 4 * ((grub_disk_addr_t) blksz / 4 + 1)) > + if (fileblock < blksz_quarter * blksz_quarter) > { > - int log_perblock =3D log2_blksz + 9 - 2; > - grub_disk_addr_t rblock =3D fileblock - (INDIRECT_BLOCKS > - + blksz / 4); > - grub_uint32_t indir; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (inode->blocks.double_indir_block)) > - << log2_blksz, > - (rblock >> log_perblock) * sizeof (indir), > - sizeof (indir), &indir)) > - return grub_errno; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (indir)) > - << log2_blksz, > - (rblock & ((1 << log_perblock) - 1)) * sizeof (indir), > - sizeof (indir), &indir)) > - return grub_errno; > - > - > - blknr =3D grub_le_to_cpu32 (indir); > + indir =3D inode->blocks.double_indir_block; > + shift =3D 1; > + goto indirect; > } > - /* triple indirect. */ > - else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * ((grub_disk_addr_= t) blksz / 4 + 1) > - + ((grub_disk_addr_t) blksz / 4) * ((grub_disk_addr_t) blksz / 4) > - * ((grub_disk_addr_t) blksz / 4 + 1)) > + fileblock -=3D blksz_quarter * blksz_quarter; > + /* Triple indirect. */ > + if (fileblock < blksz_quarter * blksz_quarter * (blksz_quarter + 1))= > { > - int log_perblock =3D log2_blksz + 9 - 2; > - grub_disk_addr_t rblock =3D fileblock - (INDIRECT_BLOCKS + blksz= / 4 > - * (blksz / 4 + 1)); > - grub_uint32_t indir; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (inode->blocks.triple_indir_block)) > - << log2_blksz, > - ((rblock >> log_perblock) >> log_perblock) > - * sizeof (indir), sizeof (indir), &indir)) > - return grub_errno; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (indir)) > - << log2_blksz, > - ((rblock >> log_perblock) > - & ((1 << log_perblock) - 1)) * sizeof (indir), > - sizeof (indir), &indir)) > - return grub_errno; > - > - if (grub_disk_read (data->disk, > - ((grub_disk_addr_t) > - grub_le_to_cpu32 (indir)) > - << log2_blksz, > - (rblock & ((1 << log_perblock) - 1)) > - * sizeof (indir), sizeof (indir), &indir)) > - return grub_errno; > - > - blknr =3D grub_le_to_cpu32 (indir); > + indir =3D inode->blocks.triple_indir_block; > + shift =3D 2; > + goto indirect; > } > - else > - { > - grub_error (GRUB_ERR_BAD_FS, > - "ext2fs doesn't support quadruple indirect blocks"); > - } > - > - return blknr; > + return grub_error (GRUB_ERR_BAD_FS, > + "ext2fs doesn't support quadruple indirect blocks"); > + > +indirect: > + do { > + if (grub_disk_read (data->disk, > + ((grub_disk_addr_t) grub_le_to_cpu32 (indir)) > + << log2_blksz, > + ((fileblock >> (log_perblock * shift)) > + & ((1 << log_perblock) - 1)) > + * sizeof (indir), > + sizeof (indir), &indir)) > + return grub_errno; > + } while (shift--); > + > + return grub_le_to_cpu32 (indir); > } > =20 > /* Read LEN bytes from the file described by DATA starting with byte >=20 ------enig2IOFCDIPUDOIFOMFFEJFD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlKDvbYACgkQmBXlbbo5nOsEOgEAiAhR9IZsKIq7t881RT5hcYhO 6mRsE6devLCfWripvt8A/2oBomrBboFMV1aDLWoEOzx2kjAOdEqZD6tGDUsz+p3F =CXfD -----END PGP SIGNATURE----- ------enig2IOFCDIPUDOIFOMFFEJFD--