* [PATCH] scsi: sr: propagate read-only status to block layer via set_disk_ro()
@ 2026-03-30 12:21 Daan De Meyer
0 siblings, 0 replies; only message in thread
From: Daan De Meyer @ 2026-03-30 12:21 UTC (permalink / raw)
To: linux-scsi; +Cc: James.Bottomley, martin.petersen, Daan De Meyer, 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, MRW-W, etc.), writeable remains 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 checks BLKROGET to decide whether to run fsck in
no-repair mode (-n). Without the read-only flag, fsck attempts writes
that produce I/O errors.
This is in contrast to the sd driver (SCSI disks), which has called
set_disk_ro() based on the MODE SENSE Write Protect bit since before
the beginning of the git history.
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.j.demeyer@gmail.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-03-30 12:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 12:21 [PATCH] 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