Skip to contentSkip to conversation

Allow random write for PDT 5 profile 2 Removable Disk

PATCH New John McKell 1 participant 1 message Feb 11, 2004

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

PATCH 1/1 Allow random write for PDT 5 profile 2 Removable Disk

Jens,

I see linux-2.6.2 extends the list of writable PDT x05 DVD/CD devices to include MRW, not just DVD-RAM and MO.

With that change in place, this small further patch allows write through to PDT 0x05 DVD/CD for profile x0002 Removable Disk:

a) if feature x0020 "Random Writable" present (no matter if current or not) at plug-in time, and...

b) if feature x0024 "Hardware Defect Management" present (no matter if current or not) at plug-in time, and...

c) if both features "current" at /dev/* open time (e.g., mount time), and ...

d) the device in question is not any of MRW, MRW_W, DVD_RAM, CD_R, CD_RW, DVD, DVD_R

Since 1999 MMC-2, MMC says these tests in combination say this device writes at random like DVD-RAM: no load balancing (aka wear leveling) required and blocks of the size the x0020 feature reports (64 KiB if like CD, 32 KiB if like DVD).

This composite version of this patch includes the already posted patch:

Subject:[PATCH] DVD-R capability flag set incorrectly, /proc
formatting fix
http://marc.theaimsgroup.com/?l=linux-scsi&m=107637086904512&w=2

Please let me know if you'd rather have an incremental patch.

---John McKell

include/linux/cdrom.h +32 -1
@@ -721,7 +721,9 @@ struct request_sense {
 /*
  * feature profile
  */
-#define CDF_MRW		0x28
+#define CDF_RWRT	0x0020
+#define CDF_HWDM	0x0024
+#define CDF_MRW		0x0028
 
 /*
  * media status bits
@@ -770,6 +772,34 @@ struct mrw_feature_desc {
 	__u8 reserved5;
 };
 
+/* cf. mmc4r02g.pdf 5.3.10 Random Writable Feature (0020h) pg 197 of 635 */
+struct rwrt_feature_desc {	
+	__u16 feature_code;
+#if defined(__BIG_ENDIAN_BITFIELD)
+	__u8 reserved1		: 2;
+	__u8 feature_version	: 4;
+	__u8 persistent		: 1;
+	__u8 curr		: 1;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 curr		: 1;
+	__u8 persistent		: 1;
+	__u8 feature_version	: 4;
+	__u8 reserved1		: 2;
+#endif
+	__u8 add_len;
+	__u32 last_lba;
+	__u32 block_size;
+	__u16 blocking;
+#if defined(__BIG_ENDIAN_BITFIELD)
+	__u8 reserved2		: 7;
+	__u8 page_present	: 1;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 page_present	: 1;
+	__u8 reserved2		: 7;
+#endif
+	__u8 reserved3;
+};
+
 typedef struct {
 	__u16 disc_information_length;
 #if defined(__BIG_ENDIAN_BITFIELD)
@@ -1129,6 +1159,7 @@ struct media_event_desc {
 
 extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
 extern int cdrom_is_mrw(struct cdrom_device_info *cdi, int *write);
+extern int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write);
 
 #endif  /* End of kernel only stuff */ 
 
drivers/ide/ide-cd.c +8 -2
@@ -2911,6 +2911,8 @@ static int ide_cdrom_register (ide_drive
 		devinfo->mask |= CDC_MRW;
 	if (!CDROM_CONFIG_FLAGS(drive)->mrw_w)
 		devinfo->mask |= CDC_MRW_W;
+	if (!CDROM_CONFIG_FLAGS(drive)->ram)
+		devinfo->mask |= CDC_RAM;
 
 	return register_cdrom(devinfo);
 }
@@ -2946,7 +2948,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, mrw_write = 0;
+	int nslots = 1, mrw_write = 0, ram_write = 0;
 
 	if (drive->media == ide_optical) {
 		CDROM_CONFIG_FLAGS(drive)->mo_drive = 1;
@@ -2982,7 +2984,11 @@ int ide_cdrom_probe_capabilities (ide_dr
 			CDROM_CONFIG_FLAGS(drive)->ram = 1;
 		}
 	}
-
+	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)
drivers/scsi/sr.c +10 -4
@@ -693,7 +693,7 @@ Enomem:
 static void get_capabilities(struct scsi_cd *cd)
 {
 	unsigned char *buffer;
-	int rc, n, mrw_write = 0, mrw = 1;
+	int rc, n, mrw_write = 0, mrw = 1,ram_write=0;
 	struct scsi_mode_data data;
 	struct scsi_request *SRpnt;
 	unsigned char cmd[MAX_COMMAND_SIZE];
@@ -775,6 +775,12 @@ static void get_capabilities(struct scsi
 	if (!mrw_write)
 		cd->cdi.mask |= CDC_MRW_W;
 
+	if (cdrom_is_random_writable(&cd->cdi, &ram_write)) {
+		cd->cdi.mask |= CDC_RAM;
+	}
+	if (!ram_write)
+		cd->cdi.mask |= CDC_RAM;
+
 	n = data.header_length + data.block_descriptor_length;
 	cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
 	cd->readcd_known = 1;
@@ -795,10 +801,9 @@ static void get_capabilities(struct scsi
 	if ((buffer[n + 2] & 0x8) == 0)
 		/* not a DVD drive */
 		cd->cdi.mask |= CDC_DVD;
-	if ((buffer[n + 3] & 0x20) == 0) {
+	if ((buffer[n + 3] & 0x20) == 0)
 		/* can't write DVD-RAM media */
 		cd->cdi.mask |= CDC_DVD_RAM;
-	} else
 	if ((buffer[n + 3] & 0x10) == 0)
 		/* can't write DVD-R media */
 		cd->cdi.mask |= CDC_DVD_R;
@@ -825,7 +830,8 @@ static void get_capabilities(struct scsi
 	/*
 	 * 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_RAM)) != 
+	    (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM))
 		cd->device->writeable = 1;
 
 	scsi_release_request(SRpnt);
drivers/cdrom/cdrom.c +105 -4

142 lines not on this page · raw message