From: Mihai Moldovan <ionic@ionic.de>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: [PATCH v2 2/7] biosdisk: restore LBA mode after read/write failures
Date: Sun, 24 May 2020 14:25:12 +0200 [thread overview]
Message-ID: <20200524122517.5010-3-ionic@ionic.de> (raw)
In-Reply-To: <20200524122517.5010-1-ionic@ionic.de>
Falling back to the old-style CHS mode after read failures is a valid
error recovery technique, but read failures can just happen. One
prominent example of that is trying to read the (somewhat) inaccessible
end sectors on newer disks with old, buggy system firmware.
Restore LBA access mode after an old-style CHS mode read/write try
again. This might lead to additional read/write operations (in case they
fail again), but also fixes issues like the biosdisk constantly being
unable to read data off sectors that are located behind the (shy of)
8-GB-mark.
---
grub-core/disk/i386/pc/biosdisk.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c
index 044bc48f3..3d55e68f8 100644
--- a/grub-core/disk/i386/pc/biosdisk.c
+++ b/grub-core/disk/i386/pc/biosdisk.c
@@ -990,11 +990,27 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
* sectors, fall back to the CHS mode ...
*/
grub_err_t chs_read = GRUB_ERR_NONE;
+
+ /* Save old data first. */
+ grub_uint64_t old_total_sectors = disk->total_sectors;
+
+ /*
+ * Switch into CHS mode and call the old-style reading code path.
+ */
data->flags &= ~GRUB_BIOSDISK_FLAG_LBA;
disk->total_sectors = data->cylinders * data->heads * data->sectors;
-
chs_read = grub_biosdisk_rw (cmd, disk, sector, size, segment);
+ /*
+ * Whatever happened, restore LBA access.
+ *
+ * We don't want the biosdisk instance to permanently degrade into
+ * an old-style CHS access mode after a read failure. Read failures
+ * can happen, especially for the end sectors.
+ */
+ data->flags |= GRUB_BIOSDISK_FLAG_LBA;
+ disk->total_sectors = old_total_sectors;
+
/* Pass CHS operation result through. */
return chs_read;
}
--
2.25.1
next prev parent reply other threads:[~2020-05-24 12:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-24 12:25 [PATCH v2 0/7] support >512b sector disks with old/buggy firmware Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 1/7] biosdisk: autodetect hardware sector size (opt-in) Mihai Moldovan
2020-05-24 12:25 ` Mihai Moldovan [this message]
2020-05-24 12:25 ` [PATCH v2 3/7] setup: add support for native sector addressing w/ 512-bytes lengths Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 4/7] grub-install: hook up --emu-512b to sector size autodetection in biosdisk Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 5/7] docs/grub: document --emu-512b install option Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 6/7] diskfilter: write out currently scanned partition Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 7/7] gpt: respect native sector size if set/detected Mihai Moldovan
2020-05-27 7:29 ` [PATCH v2 0/7] support >512b sector disks with old/buggy firmware Mihai Moldovan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200524122517.5010-3-ionic@ionic.de \
--to=ionic@ionic.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.