From: Florian Fuchs <fuchsfl@gmail.com>
To: linux-sh@vger.kernel.org,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Artur Rojek <contact@artur-rojek.eu>
Cc: Adrian McMenamin <adrianmcmenamin@gmail.com>,
linux-kernel@vger.kernel.org, Florian Fuchs <fuchsfl@gmail.com>
Subject: [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open
Date: Sun, 19 Apr 2026 18:28:23 +0200 [thread overview]
Message-ID: <20260419162823.2829286-3-fuchsfl@gmail.com> (raw)
In-Reply-To: <20260419162823.2829286-1-fuchsfl@gmail.com>
Update the gendisk capacity of the media. Without the capacity, the block
reads fail before reaching the request queue, which prevented ISO9660
mounts. Refresh the capacity from the TOC leadout in gdrom_bdops_open()
so it checks the inserted media.
Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
---
v1->v2: no change for gdrom_update_capacity(), but for
gdrom_bdops_open(): handle the failure case when
gdrom_update_capacity() fails but previous cdrom_open() succeeded,
to cleanup the successful cdrom_open() with cdrom_release()
v1: https://lore.kernel.org/linux-sh/20260405082330.4104672-3-fuchsfl@gmail.com/
---
drivers/cdrom/gdrom.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 89938d9b2825..fb95288fad72 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -474,6 +474,25 @@ static const struct cdrom_device_ops gdrom_ops = {
CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
};
+static int gdrom_update_capacity(void)
+{
+ sector_t cap;
+ int ret;
+
+ if (gdrom_drivestatus(gd.cd_info, CDSL_CURRENT) != CDS_DISC_OK) {
+ set_capacity(gd.disk, 0);
+ return -ENOMEDIUM;
+ }
+ ret = gdrom_readtoc_cmd(gd.toc, 0);
+ if (ret) {
+ set_capacity(gd.disk, 0);
+ return ret;
+ }
+ cap = (sector_t)get_entry_lba(gd.toc->leadout) * GD_TO_BLK;
+ set_capacity(gd.disk, cap);
+ return 0;
+}
+
static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
{
int ret;
@@ -482,6 +501,12 @@ static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
mutex_lock(&gdrom_mutex);
ret = cdrom_open(gd.cd_info, mode);
+ if (ret)
+ goto out;
+ ret = gdrom_update_capacity();
+ if (ret)
+ cdrom_release(gd.cd_info);
+out:
mutex_unlock(&gdrom_mutex);
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2026-04-19 16:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 16:28 [PATCH v2 0/2] cdrom: gdrom: fix block I/O and capacity setting Florian Fuchs
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-19 16:50 ` Artur Rojek
2026-04-20 10:20 ` Adrian McMenamin
2026-04-20 11:01 ` John Paul Adrian Glaubitz
2026-04-20 12:29 ` Adrian McMenamin
2026-04-19 16:28 ` Florian Fuchs [this message]
2026-04-19 16:59 ` [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open Artur Rojek
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=20260419162823.2829286-3-fuchsfl@gmail.com \
--to=fuchsfl@gmail.com \
--cc=adrianmcmenamin@gmail.com \
--cc=contact@artur-rojek.eu \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox