|
|
fd0330 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
fd0330 |
From: Mukesh Kumar Chaurasiya <mchauras@linux.vnet.ibm.com>
|
|
|
fd0330 |
Date: Thu, 9 Feb 2023 13:09:16 +0530
|
|
|
fd0330 |
Subject: [PATCH] osdep/linux/hostdisk: Modify sector by sysfs as disk sector
|
|
|
fd0330 |
|
|
|
fd0330 |
The disk sector size provided by sysfs file system considers the sector
|
|
|
fd0330 |
size of 512 irrespective of disk sector size, thus causing the read by
|
|
|
fd0330 |
the GRUB to an incorrect offset from what was originally intended.
|
|
|
fd0330 |
|
|
|
fd0330 |
Considering the 512 sector size of sysfs data the actual sector needs to
|
|
|
fd0330 |
be modified corresponding to disk sector size.
|
|
|
fd0330 |
|
|
|
fd0330 |
Signed-off-by: Mukesh Kumar Chaurasiya <mchauras@linux.vnet.ibm.com>
|
|
|
fd0330 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
fd0330 |
(cherry picked from commit f7564844f82b57078d601befadc438b5bc1fa01b)
|
|
|
fd0330 |
---
|
|
|
fd0330 |
grub-core/osdep/linux/hostdisk.c | 7 ++++---
|
|
|
fd0330 |
include/grub/disk.h | 7 +++++++
|
|
|
fd0330 |
2 files changed, 11 insertions(+), 3 deletions(-)
|
|
|
fd0330 |
|
|
|
fd0330 |
diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
|
|
|
fd0330 |
index 7bc99ac1c1..a9ea0bb465 100644
|
|
|
fd0330 |
--- a/grub-core/osdep/linux/hostdisk.c
|
|
|
fd0330 |
+++ b/grub-core/osdep/linux/hostdisk.c
|
|
|
fd0330 |
@@ -240,7 +240,8 @@ have_devfs (void)
|
|
|
fd0330 |
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
|
fd0330 |
|
|
|
fd0330 |
static int
|
|
|
fd0330 |
-grub_hostdisk_linux_find_partition (char *dev, grub_disk_addr_t sector)
|
|
|
fd0330 |
+grub_hostdisk_linux_find_partition (const grub_disk_t disk, char *dev,
|
|
|
fd0330 |
+ grub_disk_addr_t sector)
|
|
|
fd0330 |
{
|
|
|
fd0330 |
size_t len = strlen (dev);
|
|
|
fd0330 |
const char *format;
|
|
|
fd0330 |
@@ -305,7 +306,7 @@ grub_hostdisk_linux_find_partition (char *dev, grub_disk_addr_t sector)
|
|
|
fd0330 |
if (fstat (fd, &st) < 0
|
|
|
fd0330 |
|| !grub_util_device_is_mapped_stat (&st)
|
|
|
fd0330 |
|| !grub_util_get_dm_node_linear_info (st.st_rdev, 0, 0, &start))
|
|
|
fd0330 |
- start = grub_util_find_partition_start_os (real_dev);
|
|
|
fd0330 |
+ start = grub_disk_to_native_sector (disk, grub_util_find_partition_start_os (real_dev));
|
|
|
fd0330 |
/* We don't care about errors here. */
|
|
|
fd0330 |
grub_errno = GRUB_ERR_NONE;
|
|
|
fd0330 |
|
|
|
fd0330 |
@@ -386,7 +387,7 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
|
|
|
fd0330 |
&& strncmp (dev, "/dev/", 5) == 0)
|
|
|
fd0330 |
{
|
|
|
fd0330 |
if (sector >= part_start)
|
|
|
fd0330 |
- is_partition = grub_hostdisk_linux_find_partition (dev, part_start);
|
|
|
fd0330 |
+ is_partition = grub_hostdisk_linux_find_partition (disk, dev, part_start);
|
|
|
fd0330 |
else
|
|
|
fd0330 |
*max = part_start - sector;
|
|
|
fd0330 |
}
|
|
|
fd0330 |
diff --git a/include/grub/disk.h b/include/grub/disk.h
|
|
|
fd0330 |
index 06210a7049..881addcc77 100644
|
|
|
fd0330 |
--- a/include/grub/disk.h
|
|
|
fd0330 |
+++ b/include/grub/disk.h
|
|
|
fd0330 |
@@ -208,6 +208,13 @@ grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector)
|
|
|
fd0330 |
return sector << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
|
|
|
fd0330 |
}
|
|
|
fd0330 |
|
|
|
fd0330 |
+/* Convert from GRUB native disk sized sector to disk sized sector. */
|
|
|
fd0330 |
+static inline grub_disk_addr_t
|
|
|
fd0330 |
+grub_disk_to_native_sector (grub_disk_t disk, grub_disk_addr_t sector)
|
|
|
fd0330 |
+{
|
|
|
fd0330 |
+ return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
|
|
|
fd0330 |
+}
|
|
|
fd0330 |
+
|
|
|
fd0330 |
/* This is called from the memory manager. */
|
|
|
fd0330 |
void grub_disk_cache_invalidate_all (void);
|
|
|
fd0330 |
|