Commit 2b0bcc8b authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] fix blockdev --getro for sr, sd, ide-floppy

From: John McKell <mckellj@iomega.com>

This 2.6.1 patch works by setting gendisk->policy to the correct value
during initialization as the various drivers decide whether or not the disk
is writeable.  This patch persuades "blockdev --getro ..." to correctly
report the read-only state of a newly inserted disk.  This patch applies to
sr.c, sd.c and ide-floppy.c.  ide-cd.c already has this functionality built
into it.

Using an Iomega Zip drive as the test case...

Without the patch, I always see:

$ sudo blockdev --getro /dev/sda
0
$

That's only correct for writeable disks though.  Only when the patch
is applied do I see a write-protected disk described correctly:

$ sudo blockdev --getro /dev/sda
1
$
parent d11e9847
...@@ -1317,6 +1317,7 @@ static int idefloppy_get_flexible_disk_page (ide_drive_t *drive) ...@@ -1317,6 +1317,7 @@ static int idefloppy_get_flexible_disk_page (ide_drive_t *drive)
} }
header = (idefloppy_mode_parameter_header_t *) pc.buffer; header = (idefloppy_mode_parameter_header_t *) pc.buffer;
floppy->wp = header->wp; floppy->wp = header->wp;
set_disk_ro(drive->disk, floppy->wp);
page = (idefloppy_flexible_disk_page_t *) (header + 1); page = (idefloppy_flexible_disk_page_t *) (header + 1);
page->transfer_rate = ntohs(page->transfer_rate); page->transfer_rate = ntohs(page->transfer_rate);
......
...@@ -1089,6 +1089,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, ...@@ -1089,6 +1089,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
int res; int res;
struct scsi_mode_data data; struct scsi_mode_data data;
set_disk_ro(sdkp->disk, 0);
if (sdkp->device->skip_ms_page_3f) { if (sdkp->device->skip_ms_page_3f) {
printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname); printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname);
return; return;
...@@ -1120,6 +1121,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, ...@@ -1120,6 +1121,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
"%s: test WP failed, assume Write Enabled\n", diskname); "%s: test WP failed, assume Write Enabled\n", diskname);
} else { } else {
sdkp->write_prot = ((data.device_specific & 0x80) != 0); sdkp->write_prot = ((data.device_specific & 0x80) != 0);
set_disk_ro(sdkp->disk, sdkp->write_prot);
printk(KERN_NOTICE "%s: Write Protect is %s\n", diskname, printk(KERN_NOTICE "%s: Write Protect is %s\n", diskname,
sdkp->write_prot ? "on" : "off"); sdkp->write_prot ? "on" : "off");
printk(KERN_DEBUG "%s: Mode Sense: %02x %02x %02x %02x\n", printk(KERN_DEBUG "%s: Mode Sense: %02x %02x %02x %02x\n",
......
...@@ -712,6 +712,9 @@ static void get_capabilities(struct scsi_cd *cd) ...@@ -712,6 +712,9 @@ static void get_capabilities(struct scsi_cd *cd)
"" ""
}; };
/* Set read only initially */
set_disk_ro(cd->disk, 1);
/* allocate a request for the TEST_UNIT_READY */ /* allocate a request for the TEST_UNIT_READY */
SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL); SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
if (!SRpnt) { if (!SRpnt) {
...@@ -825,8 +828,11 @@ static void get_capabilities(struct scsi_cd *cd) ...@@ -825,8 +828,11 @@ static void get_capabilities(struct scsi_cd *cd)
/* /*
* if DVD-RAM of MRW-W, we are randomly writeable * if DVD-RAM of MRW-W, we are randomly writeable
*/ */
if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W)) != (CDC_DVD_RAM | CDC_MRW_W)) if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W)) !=
(CDC_DVD_RAM | CDC_MRW_W)) {
cd->device->writeable = 1; cd->device->writeable = 1;
set_disk_ro(cd->disk, 0);
}
scsi_release_request(SRpnt); scsi_release_request(SRpnt);
kfree(buffer); kfree(buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment