public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] scsi: sr: propagate read-only status to block layer via set_disk_ro()
@ 2026-04-15  6:56 Daan De Meyer
  0 siblings, 0 replies; only message in thread
From: Daan De Meyer @ 2026-04-15  6:56 UTC (permalink / raw)
  To: linux-scsi; +Cc: James.Bottomley, martin.petersen, Daan De Meyer

The sr driver tracks whether a CD-ROM drive supports writing via the
cd->writeable flag, which is determined from the drive's MODE SENSE
capabilities page (page 0x2A). When the drive does not report any write
capabilities (CD-RW, DVD-RAM, etc.), writeable is supposed to remain 0
and write requests are rejected in sr_init_command().

However, this information is never propagated to the block layer via
set_disk_ro(). As a result, BLKROGET on a CD-ROM device always returns
0 (writable), even when the drive has no write capabilities and writes
will inevitably fail. This causes problems for userspace that relies on
BLKROGET to determine whether a block device is read-only. For example,
systemd's loop device setup uses BLKROGET to decide whether to create a
loop device with LO_FLAGS_READ_ONLY. Without the read-only flag, writes
pass through the loop device to the CD-ROM and fail with I/O errors.
systemd-fsck similarly checks BLKROGET to decide whether to run fsck in
no-repair mode (-n).

The sd driver (SCSI disks) does not have this problem because it checks
the MODE SENSE Write Protect bit and calls set_disk_ro() accordingly.
The sr driver cannot use the same approach because the MMC specification
does not define the WP bit in the MODE SENSE device-specific parameter
byte for CD-ROM devices.

Fix this by calling set_disk_ro(disk, !cd->writeable) in sr_probe()
after get_capabilities() has determined the drive's write support.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Daan De Meyer <daan@amutable.com>
---
 drivers/scsi/sr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 7adb2573f50d..8ed002f82e36 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -684,6 +684,7 @@ static int sr_probe(struct scsi_device *sdev)
 	sr_vendor_init(cd);
 
 	set_capacity(disk, cd->capacity);
+	set_disk_ro(disk, !cd->writeable);
 	disk->private_data = cd;
 
 	if (register_cdrom(disk, &cd->cdi))
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-15  6:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15  6:56 [PATCH RESEND] scsi: sr: propagate read-only status to block layer via set_disk_ro() Daan De Meyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox