Received: from list by lists.gnu.org with archive (Exim 4.71) id 1es5F0-0002ms-Q0 for mharc-grub-devel@gnu.org; Sat, 03 Mar 2018 06:22:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1es5Ey-0002mX-2u for grub-devel@gnu.org; Sat, 03 Mar 2018 06:22:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1es5Eu-0005YP-S8 for grub-devel@gnu.org; Sat, 03 Mar 2018 06:22:12 -0500 Received: from mail.38.de ([81.209.249.38]:33069) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1es5Eu-0005Xg-Dw for grub-devel@gnu.org; Sat, 03 Mar 2018 06:22:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=38.de; s=mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To:Subject; bh=xF5Rh0C8Mb2kdRmbKxxDUbej7hPJqqP8yhjv3BO8JzA=; b=CUVa3iYXvPjE6TbXLBno1PmSxL3wiFp5BJL2p0BDsnW3R9wPDUMC8h/jeXetKd48ITB7UjOTJw0sx/F1T6ILd97F2VJC3qYv+vigwPZdKUv5UgA0MDtG50V/4/EWMJb3eMLCDKNDqxxRvlm8fgqWiY9wmvEQxV5WKz7CE72YS+Y=; Received: from x59cc996b.dyn.telefonica.de ([89.204.153.107] helo=[192.168.1.3]) by mail.38.de with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.80.1) (envelope-from ) id 1es5Er-00071t-KS for grub-devel@gnu.org; Sat, 03 Mar 2018 12:22:05 +0100 Subject: Re: [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads To: grub-devel@gnu.org References: <6708981a-8de3-8b88-d3e9-e75f75f5849e@38.de> From: "C. Masloch" Message-ID: <414a7d7b-55b2-9aa1-2314-095e6d96decd@38.de> Date: Sat, 3 Mar 2018 12:22:04 +0100 MIME-Version: 1.0 In-Reply-To: <6708981a-8de3-8b88-d3e9-e75f75f5849e@38.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 81.209.249.38 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: Sat, 03 Mar 2018 11:22:13 -0000 Hello, Was this overlooked? I think I should check whether dev->disk->data actually is a (struct grub_biosdisk_data *) but I don't know how! Regards, ecm On at 2018-02-01 15:51 +01:00, C. Masloch wrote: > > These fields must reflect the ROM-BIOS's geometry for CHS-based > loaders to correctly load their next stage. Most loaders do not > query the ROM-BIOS (Int13.08), relying on the BPB fields to hold > the correct values already. > > Tested with lDebug booted in qemu via grub2's > FreeDOS direct loading support, refer to > https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug > (For this test, lDebug's iniload.asm must be assembled with > -D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.) > > Signed-off-by: C. Masloch > --- > grub-core/loader/i386/pc/chainloader.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/grub-core/loader/i386/pc/chainloader.c > b/grub-core/loader/i386/pc/chainloader.c > index 18220b7aa..ef3a322b7 100644 > --- a/grub-core/loader/i386/pc/chainloader.c > +++ b/grub-core/loader/i386/pc/chainloader.c > @@ -19,6 +19,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -86,9 +87,16 @@ grub_chainloader_unload (void) > void > grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl) > { > - grub_uint32_t part_start = 0; > + grub_uint32_t part_start = 0, heads = 0, sectors = 0; > if (dev && dev->disk) > - part_start = grub_partition_get_start (dev->disk->partition); > + { > + part_start = grub_partition_get_start (dev->disk->partition); > + if (dev->disk->data) > + { > + heads = ((struct grub_biosdisk_data *)(dev->disk->data))->heads; > + sectors = ((struct grub_biosdisk_data > *)(dev->disk->data))->sectors; > + } > + } > if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name, > "NTFS", 4) == 0) > { > @@ -127,12 +135,20 @@ grub_chainloader_patch_bpb (void *bs, > grub_device_t dev, grub_uint8_t dl) > { > bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); > bpb->version_specific.fat12_or_fat16.num_ph_drive = dl; > + if (sectors) > + bpb->sectors_per_track = grub_cpu_to_le16 (sectors); > + if (heads) > + bpb->num_heads = grub_cpu_to_le16 (heads); > return; > } > if (bpb->version_specific.fat32.sectors_per_fat_32) > { > bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); > bpb->version_specific.fat32.num_ph_drive = dl; > + if (sectors) > + bpb->sectors_per_track = grub_cpu_to_le16 (sectors); > + if (heads) > + bpb->num_heads = grub_cpu_to_le16 (heads); > return; > } > break; >