Skip to content

Commit 20bd1d0

Browse files
jeremyclinemartinkpetersen
authored andcommitted
scsi: sd: Keep disk read-only when re-reading partition
If the read-only flag is true on a SCSI disk, re-reading the partition table sets the flag back to false. To observe this bug, you can run: 1. blockdev --setro /dev/sda 2. blockdev --rereadpt /dev/sda 3. blockdev --getro /dev/sda This commit reads the disk's old state and combines it with the device disk-reported state rather than unconditionally marking it as RW. Reported-by: Li Ning <[email protected]> Signed-off-by: Jeremy Cline <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 6a2cf8d commit 20bd1d0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/sd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
26242624
int res;
26252625
struct scsi_device *sdp = sdkp->device;
26262626
struct scsi_mode_data data;
2627+
int disk_ro = get_disk_ro(sdkp->disk);
26272628
int old_wp = sdkp->write_prot;
26282629

26292630
set_disk_ro(sdkp->disk, 0);
@@ -2664,7 +2665,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
26642665
"Test WP failed, assume Write Enabled\n");
26652666
} else {
26662667
sdkp->write_prot = ((data.device_specific & 0x80) != 0);
2667-
set_disk_ro(sdkp->disk, sdkp->write_prot);
2668+
set_disk_ro(sdkp->disk, sdkp->write_prot || disk_ro);
26682669
if (sdkp->first_scan || old_wp != sdkp->write_prot) {
26692670
sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
26702671
sdkp->write_prot ? "on" : "off");

0 commit comments

Comments
 (0)