Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pNnsz-00007s-Aa for mharc-grub-devel@gnu.org; Thu, 02 Feb 2023 23:41:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNnsx-00007U-HS for grub-devel@gnu.org; Thu, 02 Feb 2023 23:41:15 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNnsv-00046Y-Qk for grub-devel@gnu.org; Thu, 02 Feb 2023 23:41:15 -0500 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3132m4L0003315 for ; Fri, 3 Feb 2023 04:41:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=MYpUhPE8FySyAmbExPejaTtSHka2iiPNUFRzIbVNg44=; b=mr4d4Hq83z1pV7zl99wD+/985u13GFE7zLAzJC+iOX0IM7nmWMIHXK18IOzvUGgPcl7c u+djUWzUmGbiQzny/O442hul01WcJkTPqeOEhZ45uXlq4ZILG39ME+b05WHZDyxcH/MX oWqar8KwXHOcmZLXWfknYhYAyX3ZWk7jes5N450rcofnLg0aJXJQ3ummK3HthYkU57nk 3nOwccK0VArwAEIGRpOKTckwLb0or30Or+bryjOwjjheOCMzG7r9JuLBOum3g2FOX/n7 tTY6Ulp16xzN41ebq0JsQafcpJwaGTPtDhau+CqUPVBeWOAvb/BU6tYw/l2YfvpxBMHv tA== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ngr25bqcj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 03 Feb 2023 04:41:10 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 312Cxn2Z014009 for ; Fri, 3 Feb 2023 04:41:08 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3ncvshcy28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 03 Feb 2023 04:41:08 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3134f5wD41484750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Feb 2023 04:41:05 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 147182005A; Fri, 3 Feb 2023 04:41:05 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 01F462004B; Fri, 3 Feb 2023 04:41:04 +0000 (GMT) Received: from li-e1dea04c-3555-11b2-a85c-f57333552245.ibm.com.com (unknown [9.43.48.124]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Feb 2023 04:41:03 +0000 (GMT) From: Mukesh Kumar Chaurasiya To: grub-devel@gnu.org Cc: mamatha4@linux.vnet.ibm.com, avnish.chouhan@ibm.com, Mukesh Kumar Chaurasiya Subject: [PATCH] grub-core: modify sector by sysfs as disk sector Date: Fri, 3 Feb 2023 10:10:43 +0530 Message-Id: <20230203044043.343097-1-mchauras@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YSv0NKlVwqA5si3DJEKJDLODwTdtW5Xy X-Proofpoint-ORIG-GUID: YSv0NKlVwqA5si3DJEKJDLODwTdtW5Xy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-03_02,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxlogscore=905 priorityscore=1501 clxscore=1011 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030040 Received-SPF: none client-ip=148.163.158.5; envelope-from=mchauras@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Feb 2023 04:41:16 -0000 The disk sector size provided by sysfs file system considers the sector size of 512 irrespective of disk sector size, Thus causing the read by grub to an incorrect offset from what was originally intended. Considering the 512 sector size of sysfs data the actual sector needs to be modified corresponding to disk sector size. Signed-off-by: Mukesh Kumar Chaurasiya --- grub-core/osdep/linux/hostdisk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c index 07058f63a..13e4e2feb 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -197,8 +197,15 @@ have_devfs (void) #pragma GCC diagnostic ignored "-Wformat-nonliteral" +static inline grub_disk_addr_t +transform_sector (grub_disk_t disk, grub_disk_addr_t sector) +{ + return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); +} + static int -grub_hostdisk_linux_find_partition (char *dev, grub_disk_addr_t sector) +grub_hostdisk_linux_find_partition (const grub_disk_t disk, char *dev, + grub_disk_addr_t sector) { size_t len = strlen (dev); const char *format; @@ -263,7 +270,8 @@ grub_hostdisk_linux_find_partition (char *dev, grub_disk_addr_t sector) if (fstat (fd, &st) < 0 || !grub_util_device_is_mapped_stat (&st) || !grub_util_get_dm_node_linear_info (st.st_rdev, 0, 0, &start)) - start = grub_util_find_partition_start_os (real_dev); + start = transform_sector (disk, + grub_util_find_partition_start_os (real_dev)); /* We don't care about errors here. */ grub_errno = GRUB_ERR_NONE; @@ -344,7 +352,8 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f && strncmp (dev, "/dev/", 5) == 0) { if (sector >= part_start) - is_partition = grub_hostdisk_linux_find_partition (dev, part_start); + is_partition = grub_hostdisk_linux_find_partition (disk, dev, + part_start); else *max = part_start - sector; } -- 2.31.1