Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pQ1dV-0002NR-RV for mharc-grub-devel@gnu.org; Thu, 09 Feb 2023 02:46:30 -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 1pQ1dJ-0002Mw-PQ for grub-devel@gnu.org; Thu, 09 Feb 2023 02:46:20 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQ1dH-0004cy-Bz for grub-devel@gnu.org; Thu, 09 Feb 2023 02:46:17 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3197CEsS001159; Thu, 9 Feb 2023 07:46:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=HpM8X2dmp3Mtm06tpxvhC5Og9NDXqXeVFNPA7EYxkfc=; b=tM1aX5mnP7ZdVDT1jpv/bk8nyagLBBsVVVs6x416NefnHL85OLpKmW2dPX27kPEEh0xK ajLCYVlZaJs2SrHHCLFMuz49+m4Ct+jtNvJ5HLgFtGbs8xR6CG2AXNJOmNc949xAIxn2 EVaqdcB++g0AdA5Hlb5pBiXJixAi1lzqeLykSk1Lic9vdIxzmczmOvFUAk/h56ADrrFY czSo0SYLyPp9FLiQ7LmiHKG0p7oAHEV2qTGt36HXsdM9H3C1Pu+UuwjMT+8PfA02/TQB QmUCeutRRkXH1yKQTqbKyu9YNxWH/hG1qMcfQV1XX4kBWJwaG6tn4au6AXKNBlYjZhuB fg== 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 3nmv7sgrjn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Feb 2023 07:46:11 +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 318F2JMq016371; Thu, 9 Feb 2023 07:46:09 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3nhf06m4xe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Feb 2023 07:46:09 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3197k7po47186200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Feb 2023 07:46:07 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F32A42004B; Thu, 9 Feb 2023 07:46:06 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2BC720040; Thu, 9 Feb 2023 07:46:05 +0000 (GMT) Received: from li-e1dea04c-3555-11b2-a85c-f57333552245.ibm.com.com (unknown [9.43.0.5]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 9 Feb 2023 07:46:05 +0000 (GMT) From: Mukesh Kumar Chaurasiya To: grub-devel@gnu.org Cc: dkiper@net-space.pl, avnish.chouhan@ibm.com, mamatha4@linux.vnet.ibm.com, Mukesh Kumar Chaurasiya Subject: [PATCH V2] grub-core: modify sector by sysfs as disk sector Date: Thu, 9 Feb 2023 13:09:16 +0530 Message-Id: <20230209073914.2388627-1-mchauras@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <0230203044043.343097-1-mchauras@linux.vnet.ibm.com> References: <0230203044043.343097-1-mchauras@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: brgPWmwNtkeDej682P-zPOOOjc3JnAWo X-Proofpoint-ORIG-GUID: brgPWmwNtkeDej682P-zPOOOjc3JnAWo 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-09_04,2023-02-08_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 clxscore=1011 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302090070 Received-SPF: none client-ip=148.163.156.1; envelope-from=mchauras@linux.vnet.ibm.com; helo=mx0a-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, 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: Thu, 09 Feb 2023 07:46:23 -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 | 8 +++++--- include/grub/disk.h | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c index 07058f63a..fd0769e3b 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -198,7 +198,8 @@ have_devfs (void) #pragma GCC diagnostic ignored "-Wformat-nonliteral" 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 +264,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 = grub_disk_to_native_sector (disk, + grub_util_find_partition_start_os (real_dev)); /* We don't care about errors here. */ grub_errno = GRUB_ERR_NONE; @@ -344,7 +346,7 @@ 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; } diff --git a/include/grub/disk.h b/include/grub/disk.h index 25c141ea2..071b2f7df 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -208,6 +208,13 @@ grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector) return sector << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); } +/* Convert from GRUB native disk sized sector to disk sized sector. */ +static inline grub_disk_addr_t +grub_disk_to_native_sector (grub_disk_t disk, grub_disk_addr_t sector) +{ + return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); +} + /* This is called from the memory manager. */ void grub_disk_cache_invalidate_all (void); -- 2.31.1