Skip to contentSkip to conversation

CDC_WR_OVER

PATCH In review Pat LaVarre 1 participant 3 messages Nov 14, 2003 – Nov 21, 2003

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

PATCH 1/1 CDC_WR_OVER

-----Forwarded Message-----

From: Pat LaVarre <[email protected]>
Subject: [PATCH] CDC_WR_OVER
Date: 14 Nov 2003 16:11:44 -0700
...

I'm thinking 2.6.0-test9 cdrom.ko passes writes thru to a drive that accepts DVD-RAM discs, no matter if that drive also accepts DVD-RW and DVD+RW discs.

Do you agree? Is that ok? If no, when/how to do we fix it?

This issue grows more current e..g. Google tells me we now find such intermixtures as "DVD+RW 4x2.4x12, DVD-RW 4x2x12, DVD-RAM 3x, CD-RW 24x16x32" in one drive.

I guess I'm feeling confused in particular over how we can say it's ok to pass writes thru to DVD-RW discs while we say it's bad to pass writes thru to any cdrom device.

Perhaps you agree we can begin to move forward now by accepting or revising the patch of this e-mail?

---

This code distinguishes CDC_WR from CDC_DVD_RAM as we have discussed previously, but then works harder. Three steps now:

1)

Usually we try op x46 GPCMD_GET_CONFIGURATION for the header alone. Reasons Not to try now include:

a) CDC_CAN(CDC_DVD_RAM) because ide-cd/sr saw that in GPMODE_CAPABILITIES_PAGE

b) sr tried but failed to fetch GPMODE_CAPABILITIES_PAGE

2)

Usually we next fetch all the available op x46 GPCMD_GET_CONFIGURATION data. Reasons to fetch none or less than all available include:

a) Nothing beyond the header reported available.
b) Not a multiple of four bytes reported available, thus violating MMC.
c) xFFF0 estimate of MMC max of xFFFE bytes per CDB exceeded.
d) GFP_KERNEL kmalloc fails.

3)

Having fetched all the features we can, we loop thru them, one at a time. From that info we guess whether we want to pass writes thru to the device or not.

We guess yes only:

a) if CDC_CAN(CDC_DVD_RAM), or
b) if CDC_CAN(CDC_WR) and CDC_CAN(CDC_WR_OVER).

We default to !CDC_CAN(CDC_WR), but we switch to CDC_CAN(CDC_WR) if we discover current-or-not feature x0020 "Random Writable".

We default to CDC_CAN(CDC_WR_OVER), but we switch to !CDC_CAN(CDC_WR_OVER) if we discover any current-or-not "profile" other than a standard MMC profile that requires feature x0020.

---

Do you like this patch? Or pieces of it? How can I help next?

Pat LaVarre

include/linux/cdrom.h +2 -0
diff -Nur linux-2.6.0-test9/include/linux/cdrom.h linux/include/linux/cdrom.h
@@ -388,6 +388,8 @@
 #define CDC_DVD_R		0x10000	/* drive can write DVD-R */
 #define CDC_DVD_RAM		0x20000	/* drive can write DVD-RAM */
 #define CDC_MO_DRIVE		0x40000 /* drive is an MO device */
+#define CDC_WR			0x80000	/* tolerates random write */
+#define CDC_WR_OVER		0x100000 /* tolerates much rewrite */
 
 /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
 #define CDS_NO_INFO		0	/* if not implemented */
drivers/cdrom/cdrom.c +134 -1

165 lines not on this page · raw message

drivers/ide/ide-cd.c +6 -2
diff -Nur linux-2.6.0-test9/drivers/ide/ide-cd.c linux/drivers/ide/ide-cd.c
@@ -2822,7 +2822,8 @@
 				CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET |
 				CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R |
 				CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM |
-				CDC_GENERIC_PACKET | CDC_MO_DRIVE,
+				CDC_GENERIC_PACKET | CDC_MO_DRIVE |
+				CDC_WR | CDC_WR_OVER,
 	.generic_packet		= ide_cdrom_packet,
 };
 
@@ -2914,8 +2915,10 @@
 		return nslots;
 	}
 
-	if (ide_cdrom_get_capabilities(drive, &cap))
+	if (ide_cdrom_get_capabilities(drive, &cap)) {
+		; /* FIXME: mask CDC_WR */
 		return 0;
+	}
 
 	if (cap.lock == 0)
 		CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1;
@@ -3211,6 +3214,7 @@
 
 	nslots = ide_cdrom_probe_capabilities (drive);
 
+	; /* FIXME: also not ro if CDC_WR */
 	if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
 		set_disk_ro(drive->disk, 0);
 
drivers/scsi/sr.c +7 -5
diff -Nur linux-2.6.0-test9/drivers/scsi/sr.c linux/drivers/scsi/sr.c
@@ -67,7 +67,8 @@
 	(CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
 	 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
 	 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
-	 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET)
+	 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
+	 CDC_WR|CDC_WR_OVER)
 
 static int sr_probe(struct device *);
 static int sr_remove(struct device *);
@@ -327,8 +328,9 @@
 	}
 
 	if (rq_data_dir(SCpnt->request) == WRITE) {
-		if (!cd->device->writeable)
+		if ((cd->cdi.mask & CDC_WR) != 0) {
 			return 0;
+		}
 		SCpnt->cmnd[0] = WRITE_10;
 		SCpnt->sc_data_direction = SCSI_DATA_WRITE;
 	} else if (rq_data_dir(SCpnt->request) == READ) {
@@ -564,6 +566,7 @@
 			"%s/cd", sdev->devfs_name);
 	disk->driverfs_dev = &sdev->sdev_gendev;
 	register_cdrom(&cd->cdi);
+	cd->device->writeable = ((cd->cdi.mask & CDC_WR) == 0);
 	set_capacity(disk, cd->capacity);
 	disk->private_data = &cd->driver;
 	disk->queue = sdev->request_queue;
@@ -759,7 +762,8 @@
 		cd->cdi.speed = 1;
 		cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
 					 CDC_DVD | CDC_DVD_RAM |
-					 CDC_SELECT_DISC | CDC_SELECT_SPEED);
+					 CDC_SELECT_DISC | CDC_SELECT_SPEED |
+					 CDC_WR | CDC_WR_OVER);
 		scsi_release_request(SRpnt);
 		kfree(buffer);
 		printk("%s: scsi-1 drive\n", cd->cdi.name);
@@ -788,8 +792,6 @@
 	if ((buffer[n + 3] & 0x20) == 0) {
 		/* can't write DVD-RAM media */
 		cd->cdi.mask |= CDC_DVD_RAM;
-	} else {
-		cd->device->writeable = 1;
 	}
 	if ((buffer[n + 3] & 0x10) == 0)
 		/* can't write DVD-R media */
#1 lore raw
Quoted 2 lines

we can begin to move forward now by accepting or
revising the patch of this e-mail?

As yet revising, Not accepting.

In fact somehow we have moved this profile/ features/ writability patch of too many names from sr_mod.ko into cdrom.ko without actually achieving writability for devices other than DVD-RAM connected via ide-cd.ko.

Quoted 9 lines
drivers/ide/ide-cd.c +3 -1
-	if (ide_cdrom_get_capabilities(drive, &cap))
+	if (ide_cdrom_get_capabilities(drive, &cap)) {
+		; /* FIXME: mask CDC_WR */
 		return 0;
+	}
 
 	if (cap.lock == 0)
 		CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1;

drivers/ide/ide-cd.c line 3219

Quoted 6 lines
drivers/ide/ide-cd.c +1 -0
@@ -3211,6 +3214,7 @@
 
 	nslots = ide_cdrom_probe_capabilities (drive);
 
+	; /* FIXME: also not ro if CDC_WR */
 	if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
 		set_disk_ro(drive->disk, 0);

Possibly some of those conjectured ide-cd FIXME are necessary.

Now substituting ATAPI for USB, even with the patch applied to 2.6.0-test9, still we see:

$ sudo sg_scan -i
/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]  type=5
    Iomega    RRD               40.D [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
$
$ sudo sg_dd of=/dev/sg0 if=/dev/zero bs=2k count=1
1+0 records in
1+0 records out
$
$ sudo sg_inq /dev/hdd | egrep 'id'
 Vendor identification: Iomega
 Product identification: RRD
$
$ sudo dd of=/dev/hdd if=/dev/zero bs=2k count=1
dd: writing `/dev/hdd': Operation not permitted
1+0 records in
0+0 records out
$
$ grep -i permitted /usr/include/asm/errno.h
#define EPERM            1      /* Operation not permitted */
$ grep EPERM drivers/ide/ide-cd.c
$ grep EPERM drivers/cdrom/cdrom.c
$

Pat LaVarre

#2 lore raw

Kindly offline I'm told ...

Quoted 1 line

As yet revising, Not accepting.

Slowly the necessary pieces come into focus:

1) Find the writable-or-not code of sr_mod.ko.
2) Find the writable-or-not code of ide-cd.ko.
3) Move (1) and (2) into cdrom.ko.

4) Teach cdrom.ko to fetch op x46 GPCMD_GET_CONFIGURATION header.
5) Teach cdrom.ko to fetch all reportedly available op x46 data.

6) Learn that more than DVD-RAM is writable.

Quoted 4 lines
Quoted 4 lines

1) Find the writable-or-not code of sr_mod.ko.
3) Move (1) and (2) into cdrom.ko.
4) Teach cdrom.ko to fetch op x46 GPCMD_GET_CONFIGURATION header.
5) Teach cdrom.ko to fetch all reportedly available op x46 data.

All ok now.

Quoted 1 line
Quoted 1 line

2) Find the writable-or-not code of ide-cd.ko.

Not yet complete.

Quoted 1 line
Quoted 1 line

6) Learn that more than DVD-RAM is writable.

Still feels kluged.

CD-RW and DVD+RW support random rewrites if load balanced. Those designs have not pioneered a standard way of saying truly random rewrites supported, other than saying DVD-RAM.

Pat LaVarre