linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix blockdev --getro for sr, sd, ide-floppy devs
@ 2004-01-19 21:36 John McKell
  2004-01-22  8:27 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: John McKell @ 2004-01-19 21:36 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-scsi

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
$

--John McKell


diff -Nurp linux-2.6.1/drivers/ide/ide-floppy.c
linux/drivers/ide/ide-floppy.c
--- linux-2.6.1/drivers/ide/ide-floppy.c	2004-01-08 23:59:33.000000000
-0700
+++ linux/drivers/ide/ide-floppy.c	2004-01-14 08:46:26.000000000 -0700
@@ -1317,6 +1317,7 @@ static int idefloppy_get_flexible_disk_p
 	}
 	header = (idefloppy_mode_parameter_header_t *) pc.buffer;
 	floppy->wp = header->wp;
+	set_disk_ro(drive->disk, floppy->wp);
 	page = (idefloppy_flexible_disk_page_t *) (header + 1);
 
 	page->transfer_rate = ntohs(page->transfer_rate);
diff -Nurp linux-2.6.1/drivers/scsi/sd.c linux/drivers/scsi/sd.c
--- linux-2.6.1/drivers/scsi/sd.c	2004-01-08 23:59:49.000000000 -0700
+++ linux/drivers/scsi/sd.c	2004-01-14 08:46:26.000000000 -0700
@@ -1089,6 +1089,7 @@ sd_read_write_protect_flag(struct scsi_d
 	int res;
 	struct scsi_mode_data data;
 
+	set_disk_ro(sdkp->disk, 0);
 	if (sdkp->device->skip_ms_page_3f) {
 		printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname);
 		return;
@@ -1120,6 +1121,7 @@ sd_read_write_protect_flag(struct scsi_d
 		       "%s: test WP failed, assume Write Enabled\n", diskname);
 	} else {
 		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,
 		       sdkp->write_prot ? "on" : "off");
 		printk(KERN_DEBUG "%s: Mode Sense: %02x %02x %02x %02x\n",
diff -Nurp linux-2.6.1/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- linux-2.6.1/drivers/scsi/sr.c	2004-01-08 23:59:19.000000000 -0700
+++ linux/drivers/scsi/sr.c	2004-01-14 09:16:18.000000000 -0700
@@ -711,6 +711,9 @@ static void get_capabilities(struct scsi
 		""
 	};
 
+	/* Set read only initially */
+	set_disk_ro(cd->disk, 1);
+
 	/* allocate a request for the TEST_UNIT_READY */
 	SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
 	if (!SRpnt) {
@@ -790,6 +793,7 @@ static void get_capabilities(struct scsi
 		cd->cdi.mask |= CDC_DVD_RAM;
 	} else {
 		cd->device->writeable = 1;
+		set_disk_ro(cd->disk, 0);
 	}
 	if ((buffer[n + 3] & 0x10) == 0)
 		/* can't write DVD-R media */





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix blockdev --getro for sr, sd, ide-floppy devs
  2004-01-19 21:36 [PATCH] fix blockdev --getro for sr, sd, ide-floppy devs John McKell
@ 2004-01-22  8:27 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2004-01-22  8:27 UTC (permalink / raw)
  To: John McKell; +Cc: linux-scsi

On Mon, Jan 19 2004, John McKell wrote:
> 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.

Patch looks good, thanks.


-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-01-22  8:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-19 21:36 [PATCH] fix blockdev --getro for sr, sd, ide-floppy devs John McKell
2004-01-22  8:27 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).