Skip to contentSkip to conversation

fix cdrom mt rainier probe

PATCH Pat LaVarre 2 participants 12 messages Jul 13, 2004 – Jul 18, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Jens A:

--- http://www.kernel.org/pub/linux/kernel/v2.6/testing/ChangeLog-2.6.8-rc1
--- ...
[PATCH] fix cdrom mt rainier probe

Mt rainier probe must be deferred to media load time, since it requires a valid media (the drive may present a different capability based on what media is loaded). This fixes that for ide-cd and sr.
...
---

Looks like something broke in deciding disc rewritable or not?

Only for /dev/hdd PATAPI, not for /dev/scd0 USB?

I see again we have rewritable by ioctl does not imply rewritable by dd and mount. I'll blog my exploration outside, then report back if I come to understand more, but specifically so far I've seen:

$ uname -srm
Linux 2.6.7 i686
$ sudo rrd scan
/dev/scd0 is Iomega RRD 74.B rw
/dev/hdd is Iomega RRD 74.B rw
$
$ sudo dd of=/dev/scd0 bs=64K count=1 if=/dev/zero
1+0 records in
1+0 records out
$ sudo dd of=/dev/hdd bs=64K count=1 if=/dev/zero
1+0 records in
1+0 records out
$
$ uname -srm
Linux 2.6.8-rc1 i686
$ sudo rrd scan
/dev/scd0 is Iomega RRD 74.B rw
/dev/hdd is Iomega RRD 74.B rw
$
$ sudo dd of=/dev/scd0 bs=64K count=1 if=/dev/zero
1+0 records in
1+0 records out
$ sudo dd of=/dev/hdd bs=64K count=1 if=/dev/zero
dd: writing `/dev/hdd': Operation not permitted
1+0 records in
0+0 records out
$

Pat LaVarre
http://linux-pel.blog-city.com/read/728344.htm

#1 lore raw
Quoted 4 lines
Quoted 1 line

Mt rainier probe must be deferred to media load time, ...

...
something broke in deciding disc rewritable or not? ... Only for /dev/hdd PATAPI, not for /dev/scd0 USB?

Can any of us easily sketch a legit fix for this? By now we know,

a)

The key evil is not getting back 0 0 in reply to the query:

$ sudo blockdev --getro /dev/hdd /dev/scd0
1
0
$

b)

A completely bogus hack of a workaround is:

sudo blockdev --setrw /dev/hdd

c)

Below is that same completely bogus hack, expressed as a kernel patch Not suitable for kernel.org.

Pat LaVarre
http://linux-pel.blog-city.com/read/728344.htm

drivers/ide/ide-cd.c +1 -0
@@ -3251,6 +3251,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	 * set correct block size and read-only for non-ram media
 	 */
 	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
+	set_disk_ro(drive->disk, 0);
 	blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
 #if 0
#2 lore raw
Quoted 33 lines · Pat LaVarre
Quoted 4 lines
Quoted 1 line

Mt rainier probe must be deferred to media load time, ...

...
something broke in deciding disc rewritable or not? ... Only for /dev/hdd PATAPI, not for /dev/scd0 USB?

Can any of us easily sketch a legit fix for this? By now we know,

a)

The key evil is not getting back 0 0 in reply to the query:

$ sudo blockdev --getro /dev/hdd /dev/scd0
1
0
$

b)

A completely bogus hack of a workaround is:

sudo blockdev --setrw /dev/hdd

c)

Below is that same completely bogus hack, expressed as a kernel patch Not suitable for kernel.org.

Pat LaVarre
http://linux-pel.blog-city.com/read/728344.htm

drivers/ide/ide-cd.c int ide_cdrom_setup (ide_drive_t *drive) · line 3254

Quoted 4 lines
drivers/ide/ide-cd.c +1 -0
@@ -3251,6 +3251,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	 * set correct block size and read-only for non-ram media
 	 */
 	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
+	set_disk_ro(drive->disk, 0);

Trace that backwards and find out why ->ram isn't getting set.

Signature · 1 line
Jens Axboe
#3 lore raw

Jens A:

Quoted 9 lines

drivers/ide/ide-cd.c 2004-07-13 14:33:40.000000000 -0600 int ide_cdrom_setup (ide_drive_t *drive) · line 3254

Quoted 7 lines
drivers/ide/ide-cd.c 2004-07-13 14:33:40.000000000 -0600 renamed from drivers/ide/ide-cd.c 2004-07-13 08:26:05.000000000 -0600 +1 -0
@@ -3251,6 +3251,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
       * set correct block size and read-only for non-ram media
       */
      set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
+     set_disk_ro(drive->disk, 0);

Trace that backwards and find out why ->ram isn't getting set.

An answer to that helpfully concrete question is:

2.6.8-rc1 differs from 2.6.7 by lacking the three-line patch below.

Back in the ide_cdrom_probe_capabilities of 2.6.7, we were saying any drive that offered "feature" x0020 "Random Writable" was set_disk_ro rewritable. Now in 2.6.8-rc1 we accept only:

        cap.dvd_ram_write || (drive->media == ide_optical)

That criterion denies the rewritability of the drive I'm testing i.e. the "Iomega" "RRD" drive.

I'd like Linux to perceive the reality that RRD discs are as rewritable as DVD RAM discs are - can I help further?

Pat LaVarre

drivers/ide/ide-cd.c +5 -1
@@ -2925,7 +2925,7 @@ int ide_cdrom_probe_capabilities (ide_dr
 	struct cdrom_info *info = drive->driver_data;
 	struct cdrom_device_info *cdi = &info->devinfo;
 	struct atapi_capabilities_page cap;
-	int nslots = 1;
+	int nslots = 1, ram_write = 0;
 
 	if (drive->media == ide_optical) {
 		CDROM_CONFIG_FLAGS(drive)->mo_drive = 1;
@@ -2954,6 +2954,10 @@ int ide_cdrom_probe_capabilities (ide_dr
 	if (ide_cdrom_get_capabilities(drive, &cap))
 		return 0;
 
+	if (!cdrom_is_random_writable(cdi, &ram_write))
+		if (ram_write)
+			CDROM_CONFIG_FLAGS(drive)->ram = 1;
+
 	if (cap.lock == 0)
 		CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1;
 	if (cap.eject)
#4 lore raw

Jens A:

Annihilating the calls to set_disk_ro from scsi/sr.c and ide/ide-cd.c withdraws blanket write protection from all USB/ PATAPI etc. DVD/ CD devices, and instead gives to all DVD/ CD only the late, open-time, distinction between rewritable and read-only discs.

For example, with this patch applied, I see:

$ sudo blockdev --getro /dev/hdd /dev/scd0
0
0
$
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/hdd': Read-only file system
$
$ # eject read-only disc, insert rewritable disc
$
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$

As expected, I saw exactly the same results with USB /dev/scd0 as with the PATAPI /dev/hdd shown above.

Do you like this behaviour better than what we have now in 2.6.8-rc1?

(I do, because USB and PATAPI come into agreement with each other, and because Iomega RRD discs correctly become rewritable by default.)

This idea, kindly suggested to me offline, is enough simpler than learning to call set_disk_ro after each disc change that I am able to propose the specific patch quoted inline below.

In this patch you will see four parts, to give you two choices I thought you might like to consider.

1) The first part changes cdrom_open to check CDC_RAM earlier in an FMODE_WRITE open i.e. before open_for_data. I'm asking you to choose to check earlier or not.

2) The second part draws your attention to a set_disk_ro I actually did not delete. That remaining set_disk_ro dynamically forces ro true in response to particular write errors. The /* != scsi/sr.c */ text of the comment I used to draw you attention to that source line means to say that this is an asymmetry between ide/ide-cd.c and scsi/sr.c, in that only ide/ide-cd.c works this hard. I'm asking you to choose to delete that call to set_disk_ro, to comment on its asymmetry, or to leave it unchanged.

3, 4) The last two parts of the patch merely delete the once-per-plugin calls to set_disk_ro.

Pat LaVarre

drivers/cdrom/cdrom.c +5 -2
diff -urp linux-2.6.8-rc1/drivers/cdrom/cdrom.c linux-2.6.8-rc1-pel/drivers/cdrom/cdrom.c
@@ -892,13 +892,16 @@ int cdrom_open(struct cdrom_device_info 
 	if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) {
 		ret = cdi->ops->open(cdi, 1);
 	} else {
+		if (fp->f_mode & FMODE_WRITE) {
+			ret = -EROFS;
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;
+		}
 		ret = open_for_data(cdi);
 		if (ret)
 			goto err;
 		if (fp->f_mode & FMODE_WRITE) {
 			ret = -EROFS;
-			if (!CDROM_CAN(CDC_RAM))
-				goto err;
 			if (cdrom_open_write(cdi))
 				goto err;
 			ret = 0;
drivers/ide/ide-cd.c +2 -3
diff -urp linux-2.6.8-rc1/drivers/ide/ide-cd.c linux-2.6.8-rc1-pel/drivers/ide/ide-cd.c
@@ -790,7 +790,7 @@ static int cdrom_decode_status(ide_drive
 			 */
 			if (rq_data_dir(rq) == WRITE) {
 				printk("ide-cd: media marked write protected\n");
-				set_disk_ro(drive->disk, 1);
+				set_disk_ro(drive->disk, 1); /* != scsi/sr.c */
 			}
 
 			/* No point in retrying after an illegal
@@ -3248,9 +3248,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	nslots = ide_cdrom_probe_capabilities (drive);
 
 	/*
-	 * set correct block size and read-only for non-ram media
+	 * set correct block size
 	 */
-	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
 	blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
 #if 0
drivers/scsi/sr.c +0 -4
diff -urp linux-2.6.8-rc1/drivers/scsi/sr.c linux-2.6.8-rc1-pel/drivers/scsi/sr.c
@@ -775,9 +775,6 @@ 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) {
@@ -885,7 +882,6 @@ static void get_capabilities(struct scsi
 	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) !=
 			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) {
 		cd->device->writeable = 1;
-		set_disk_ro(cd->disk, 0);
 	}
 
 	scsi_release_request(SRpnt);
#5 lore raw
Quoted 30 lines · Pat LaVarre

1) The first part changes cdrom_open to check CDC_RAM earlier in an FMODE_WRITE open i.e. before open_for_data. I'm asking you to choose to check earlier or not.

2) The second part draws your attention to a set_disk_ro I actually did not delete. That remaining set_disk_ro dynamically forces ro true in response to particular write errors. The /* != scsi/sr.c */ text of the comment I used to draw you attention to that source line means to say that this is an asymmetry between ide/ide-cd.c and scsi/sr.c, in that only ide/ide-cd.c works this hard. I'm asking you to choose to delete that call to set_disk_ro, to comment on its asymmetry, or to leave it unchanged.

3, 4) The last two parts of the patch merely delete the once-per-plugin calls to set_disk_ro.

Pat LaVarre

diff -urp linux-2.6.8-rc1/drivers/cdrom/cdrom.c linux-2.6.8-rc1-pel/drivers/cdrom/cdrom.c

drivers/cdrom/cdrom.c +5 -0
@@ -892,13 +892,16 @@ int cdrom_open(struct cdrom_device_info 
 	if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) {
 		ret = cdi->ops->open(cdi, 1);
 	} else {
+		if (fp->f_mode & FMODE_WRITE) {
+			ret = -EROFS;
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;
+		}

drivers/cdrom/cdrom.c int cdrom_open(struct cdrom_device_info · line 907

Quoted 10 lines
drivers/cdrom/cdrom.c +0 -2
 		ret = open_for_data(cdi);
 		if (ret)
 			goto err;
 		if (fp->f_mode & FMODE_WRITE) {
 			ret = -EROFS;
-			if (!CDROM_CAN(CDC_RAM))
-				goto err;
 			if (cdrom_open_write(cdi))
 				goto err;
 			ret = 0;

This looks strange - cdrom_open_write() is the one that checks whether the media is suitable for writing or not. In fact, it looks as if just transposing the two checks should be fine:

                if (fp->f_mode & FMODE_WRITE) {
                        ret = -EROFS;
                        if (cdrom_open_write(cdi))
                                goto err;
                        if (!CDROM_CAN(CDC_RAM))
                                goto err;
                        ret = 0;
                }

drivers/ide/ide-cd.c static int cdrom_decode_status(ide_drive · line 794

Quoted 10 lines

diff -urp linux-2.6.8-rc1/drivers/ide/ide-cd.c linux-2.6.8-rc1-pel/drivers/ide/ide-cd.c

drivers/ide/ide-cd.c +1 -1
@@ -790,7 +790,7 @@ static int cdrom_decode_status(ide_drive
 			 */
 			if (rq_data_dir(rq) == WRITE) {
 				printk("ide-cd: media marked write protected\n");
-				set_disk_ro(drive->disk, 1);
+				set_disk_ro(drive->disk, 1); /* != scsi/sr.c */
 			}

This needs to go as well, unless you mark it writable again after close of this media.

Quoted 26 lines
drivers/ide/ide-cd.c +1 -2
 			/* No point in retrying after an illegal
@@ -3248,9 +3248,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	nslots = ide_cdrom_probe_capabilities (drive);
 
 	/*
-	 * set correct block size and read-only for non-ram media
+	 * set correct block size
 	 */
-	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
 	blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
 #if 0

diff -urp linux-2.6.8-rc1/drivers/scsi/sr.c linux-2.6.8-rc1-pel/drivers/scsi/sr.c

drivers/scsi/sr.c +0 -3
@@ -775,9 +775,6 @@ 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) {

drivers/scsi/sr.c static void get_capabilities(struct scsi · line 887

Quoted 7 lines
drivers/scsi/sr.c +0 -1
@@ -885,7 +882,6 @@ static void get_capabilities(struct scsi
 	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) !=
 			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) {
 		cd->device->writeable = 1;
-		set_disk_ro(cd->disk, 0);
 	}
 
 	scsi_release_request(SRpnt);

These are fine.

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 46 lines · Jens Axboe
Quoted 30 lines · Pat LaVarre

1) The first part changes cdrom_open to check CDC_RAM earlier in an FMODE_WRITE open i.e. before open_for_data. I'm asking you to choose to check earlier or not.

2) The second part draws your attention to a set_disk_ro I actually did not delete. That remaining set_disk_ro dynamically forces ro true in response to particular write errors. The /* != scsi/sr.c */ text of the comment I used to draw you attention to that source line means to say that this is an asymmetry between ide/ide-cd.c and scsi/sr.c, in that only ide/ide-cd.c works this hard. I'm asking you to choose to delete that call to set_disk_ro, to comment on its asymmetry, or to leave it unchanged.

3, 4) The last two parts of the patch merely delete the once-per-plugin calls to set_disk_ro.

Pat LaVarre

diff -urp linux-2.6.8-rc1/drivers/cdrom/cdrom.c linux-2.6.8-rc1-pel/drivers/cdrom/cdrom.c

drivers/cdrom/cdrom.c +5 -0
@@ -892,13 +892,16 @@ int cdrom_open(struct cdrom_device_info 
 	if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) {
 		ret = cdi->ops->open(cdi, 1);
 	} else {
+		if (fp->f_mode & FMODE_WRITE) {
+			ret = -EROFS;
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;
+		}

drivers/cdrom/cdrom.c int cdrom_open(struct cdrom_device_info · line 907

Quoted 10 lines
drivers/cdrom/cdrom.c +0 -2
 		ret = open_for_data(cdi);
 		if (ret)
 			goto err;
 		if (fp->f_mode & FMODE_WRITE) {
 			ret = -EROFS;
-			if (!CDROM_CAN(CDC_RAM))
-				goto err;
 			if (cdrom_open_write(cdi))
 				goto err;
 			ret = 0;

This looks strange - cdrom_open_write() is the one that checks whether the media is suitable for writing or not. In fact, it looks as if just transposing the two checks should be fine:

Quoted 8 lines
                if (fp->f_mode & FMODE_WRITE) {
                        ret = -EROFS;
                        if (cdrom_open_write(cdi))
                                goto err;
                        if (!CDROM_CAN(CDC_RAM))
                                goto err;
                        ret = 0;
                }

Actually, looking at the above makes it clear that we should probably just drop CDC_RAM again and just let cdrom_open_write() return whether we are allowed to open the media for write or not. Now that CDC_RAM is a per-media capability flag, it doesn't make sense to set/clear it on every open when you can just return ok or not.

But that cleanup can be applied of this patch, so please just continue.

Signature · 1 line
Jens Axboe
#7 lore raw

Jens A:

Quoted 4 lines

cdrom_open ... transposing the two checks ... cdrom_decode_status ... set_disk_ro ... needs to go ... unless ... ide_cdrom_setup ...
get_capabilities ... These are fine.

This e-mail ends with that four part patch you describe, thank you for those clear instructions.

I also specifically confirmed that deleting rq_data_dir has no side effect:

$ grep rq_data_dir include/linux/*
include/linux/blkdev.h:#define rq_data_dir(rq)          ((rq)->flags & 1)
$
Quoted 2 lines

Now that CDC_RAM is a per-media capability flag, it doesn't make sense to set/clear it on every open when you can just return ok or not.

Agreed.

I had suggested always trying a fetch of mode page x2A "Capabilities" before op x46 "GET CONFIGURATION" out of fear of legacy DVD/ CD choking over the new op.

I see in the release early often spirit we can try simplifying our host code first and waiting for someone to complain, maybe no one ever actually will.

Quoted 8 lines
Quoted 2 lines
(quoted diff) +2 -0
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;

...

Quoted 1 line

if (cdrom_open_write(cdi))

...
This looks strange -
cdrom_open_write() is the one that checks whether
the media is suitable for writing or not

Agreed.

Me thinking like this is why I don't understand how CDC_RAM ever got set in my patched PATAPI code. But since we're abandoning CDC_RAM, I won't analyse that mystery further, unless you tell me I should.

Quoted 2 lines

Date: Fri, 16 Jul 2004 14:28:45 +0200
Date: Fri, 16 Jul 2004 14:25:55 +0200

Ouch I was asleep then. (: I need to route my e-mail to my phone. :)

Pat LaVarre

drivers/cdrom/cdrom.c +2 -2
diff -urp linux-2.6.8-rc1/drivers/cdrom/cdrom.c linux-2.6.8-rc1-pel/drivers/cdrom/cdrom.c
@@ -897,10 +897,10 @@ int cdrom_open(struct cdrom_device_info 
 			goto err;
 		if (fp->f_mode & FMODE_WRITE) {
 			ret = -EROFS;
-			if (!CDROM_CAN(CDC_RAM))
-				goto err;
 			if (cdrom_open_write(cdi))
 				goto err;
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;
 			ret = 0;
 		}
 	}
drivers/ide/ide-cd.c +1 -10
diff -urp linux-2.6.8-rc1/drivers/ide/ide-cd.c linux-2.6.8-rc1-pel/drivers/ide/ide-cd.c
@@ -785,14 +785,6 @@ static int cdrom_decode_status(ide_drive
 				do_end_request = 1;
 		} else if (sense_key == ILLEGAL_REQUEST ||
 			   sense_key == DATA_PROTECT) {
-			/*
-			 * check if this was a write protected media
-			 */
-			if (rq_data_dir(rq) == WRITE) {
-				printk("ide-cd: media marked write protected\n");
-				set_disk_ro(drive->disk, 1);
-			}
-
 			/* No point in retrying after an illegal
 			   request or data protect error.*/
 			ide_dump_status (drive, "command error", stat);
@@ -3248,9 +3240,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	nslots = ide_cdrom_probe_capabilities (drive);
 
 	/*
-	 * set correct block size and read-only for non-ram media
+	 * set correct block size
 	 */
-	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
 	blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
 #if 0
drivers/scsi/sr.c +0 -4
diff -urp linux-2.6.8-rc1/drivers/scsi/sr.c linux-2.6.8-rc1-pel/drivers/scsi/sr.c
@@ -775,9 +775,6 @@ 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) {
@@ -885,7 +882,6 @@ static void get_capabilities(struct scsi
 	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) !=
 			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) {
 		cd->device->writeable = 1;
-		set_disk_ro(cd->disk, 0);
 	}
 
 	scsi_release_request(SRpnt);
#8 lore raw
Quoted 62 lines · Pat LaVarre

diff -urp linux-2.6.8-rc1/drivers/cdrom/cdrom.c linux-2.6.8-rc1-pel/drivers/cdrom/cdrom.c

drivers/cdrom/cdrom.c +2 -2
@@ -897,10 +897,10 @@ int cdrom_open(struct cdrom_device_info 
 			goto err;
 		if (fp->f_mode & FMODE_WRITE) {
 			ret = -EROFS;
-			if (!CDROM_CAN(CDC_RAM))
-				goto err;
 			if (cdrom_open_write(cdi))
 				goto err;
+			if (!CDROM_CAN(CDC_RAM))
+				goto err;
 			ret = 0;
 		}
 	}

diff -urp linux-2.6.8-rc1/drivers/ide/ide-cd.c linux-2.6.8-rc1-pel/drivers/ide/ide-cd.c

drivers/ide/ide-cd.c +1 -10
@@ -785,14 +785,6 @@ static int cdrom_decode_status(ide_drive
 				do_end_request = 1;
 		} else if (sense_key == ILLEGAL_REQUEST ||
 			   sense_key == DATA_PROTECT) {
-			/*
-			 * check if this was a write protected media
-			 */
-			if (rq_data_dir(rq) == WRITE) {
-				printk("ide-cd: media marked write protected\n");
-				set_disk_ro(drive->disk, 1);
-			}
-
 			/* No point in retrying after an illegal
 			   request or data protect error.*/
 			ide_dump_status (drive, "command error", stat);
@@ -3248,9 +3240,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
 	nslots = ide_cdrom_probe_capabilities (drive);
 
 	/*
-	 * set correct block size and read-only for non-ram media
+	 * set correct block size
 	 */
-	set_disk_ro(drive->disk, !CDROM_CONFIG_FLAGS(drive)->ram);
 	blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
 #if 0

diff -urp linux-2.6.8-rc1/drivers/scsi/sr.c linux-2.6.8-rc1-pel/drivers/scsi/sr.c

drivers/scsi/sr.c +0 -3
@@ -775,9 +775,6 @@ 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) {

drivers/scsi/sr.c static void get_capabilities(struct scsi · line 887

Quoted 7 lines
drivers/scsi/sr.c +0 -1
@@ -885,7 +882,6 @@ static void get_capabilities(struct scsi
 	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) !=
 			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) {
 		cd->device->writeable = 1;
-		set_disk_ro(cd->disk, 0);
 	}
 
 	scsi_release_request(SRpnt);

This looks perfect! Have you tested it works as expected as well, with rw and ro media?

Signature · 1 line
Jens Axboe
#9 lore raw

Jens A:

Quoted 2 lines

Have you tested it works as expected as well, with rw and ro media?

Ouch, yes, please, never assume I've tested unless I say so explicitly.

So far I've just seen the expected, with one rewritable and one read-only disc, in a pair of USB and PATAPI drives:

$ sudo plscsi /dev/scd0 /dev/hdd
export PLSCSI=/dev/scd0       // B Iomega   RRD              DB76
export PLSCSI=/dev/hdd        // @ Iomega   RRD              74.B
$
$ sudo blockdev --getro /dev/scd0 /dev/hdd
0
0
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/scd0': Read-only file system
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$
$ # swap discs
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/hdd': Read-only file system
$
Quoted 1 line

looks perfect!

Excellent, I conclude I have understood correctly.

Quoted 1 line

Have you tested ...

I trust you will tell me if I can help further.

Pat LaVarre

#10 lore raw
Quoted 24 lines · Pat LaVarre

Jens A:

Quoted 2 lines

Have you tested it works as expected as well, with rw and ro media?

Ouch, yes, please, never assume I've tested unless I say so explicitly.

So far I've just seen the expected, with one rewritable and one read-only disc, in a pair of USB and PATAPI drives:

$ sudo plscsi /dev/scd0 /dev/hdd
export PLSCSI=/dev/scd0       // B Iomega   RRD              DB76
export PLSCSI=/dev/hdd        // @ Iomega   RRD              74.B
$
$ sudo blockdev --getro /dev/scd0 /dev/hdd
0
0
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/scd0': Read-only file system
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$
Quoted 8 lines
$ # swap discs
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/hdd': Read-only file system
$

Looks good, thanks.

Quoted 3 lines
Quoted 1 line

looks perfect!

Excellent, I conclude I have understood correctly.

You have.

Quoted 3 lines
Quoted 1 line

Have you tested ...

I trust you will tell me if I can help further.

I'll start by forwarding this patch, so it at least will work in 2.6.8.

Signature · 1 line
Jens Axboe
#11 lore raw

Jens A:

Quoted 2 lines

I'll start by forwarding this patch,
so it at least will work in 2.6.8.

2.6.8-rc1-bk6 looks good here now.

diff says the patch arrived intact. tty shows the expected results.

Thank you.

Pat LaVarre

---

$ uname -msr
Linux 2.6.8-rc1-bk6 i686
$
$ sudo plscsi /dev/scd0 /dev/hdd
export PLSCSI=/dev/scd0       // B Iomega   RRD              74.B
export PLSCSI=/dev/hdd        // @ Iomega   RRD              74.B
$
$ sudo blockdev --getro /dev/scd0 /dev/hdd
0
0
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/scd0': Read-only file system
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$
$ # swap discs
$
$ sudo dd of=/dev/scd0 bs=64K seek=0 count=1 if=/dev/zero
1+0 records in
1+0 records out
$ sudo dd of=/dev/hdd bs=64K seek=0 count=1 if=/dev/zero
dd: opening `/dev/hdd': Read-only file system
$

---