scsi: sr: propagate read-only status to block layer via set_disk_ro()
PATCH RESEND 1/1 scsi: sr: propagate read-only status to block layer via set_disk_ro()
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.
--- drivers/scsi/sr.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/sr.c +1 -0
@@ -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))
Signature · 1 line
2.53.0