* CDC_RAM for lk 2.4, PATCH proposed
@ 2004-04-15 16:52 Pat LaVarre
2004-04-16 12:09 ` Jens Axboe
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-04-15 16:52 UTC (permalink / raw)
To: axboe; +Cc: mckellj, linux-scsi
Jens A:
Would you consider for 2.4.27, a patch written to give us CDC_RAM alone?
I ask because I notice, we don't need the problematic op x46
GPCMD_GET_CONFIGURATION feature x0028 MRW for 2.4.27 to support
CDC_RAM. We only need that for MRW.
Pat LaVarre
P.S.
I speak from a context of you & John M having already done most of the
work:
--- http://sourceforge.net/projects/iomrrdtools/
--- Release Name: writable-patch-0.2
--- http://sourceforge.net/project/shownotes.php?release_id=229527
...
http://w1.894.telia.com/~u89404340/patches/packet/2.4/cd-mrw-2.4.23-rc1.patch.bz2
...
not ... complete MRW [like] lk 2.6.2+
one drive ... respond incorrectly
when doing the GET_CONFIGURATION with 0x28 ...
main reason ... not introduced into lk 2.4.
---
I ask because people connecting the recently announced Iomega RRD drives
have asked me how to mkfs ext in 2.4, to which my answer as yet is
sorry, can't help you, except for people willing to mkfs in /dev/loop
and sg_dd the disc image across.
Also I'm guessing feature fetch per se could be broadly compatible,
because today I grabbed one sample of one of the massively distributed
Microsoft XP SP1 instances beginning USB life:
https://lists.one-eyed-alien.net/pipermail/usb-storage/2004-April/000214.html
The first three commands I see are:
-i x24 -y "12 00:00:00 24 00" // standard "INQUIRY" GPCMD_INQUIRY
-i 8 -y "46 00 00:00:00:00 00 00:08 00" // header alone of GPCMD_GET_CONFIGURATION
-i x80 -y "46 00 00:00:00:00 00 00:80 00" // total available length
...
Soon thereafter my sample proceeds with such familiar &
sufficient-to-discover-rewritable talk as:
-i x20 -y "5A 08 2A:00:00:00 00 00:20 00" // "Capabilities" GPMODE_CAPABILITIES_PAGE
...
-i x0C -y "46 00 00:20:00:00 00 00:0C 00" // "Random Writable" CDF_RWRT
...
-i x0C -y "46 00 00:24:00:00 00 00:0C 00" // "Hardware Defect Management" CDF_HWDM
...
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-04-15 16:52 CDC_RAM for lk 2.4, PATCH proposed Pat LaVarre
@ 2004-04-16 12:09 ` Jens Axboe
2004-04-23 22:25 ` John McKell
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-04-16 12:09 UTC (permalink / raw)
To: Pat LaVarre; +Cc: mckellj, linux-scsi
On Thu, Apr 15 2004, Pat LaVarre wrote:
> Jens A:
>
> Would you consider for 2.4.27, a patch written to give us CDC_RAM alone?
>
> I ask because I notice, we don't need the problematic op x46
> GPCMD_GET_CONFIGURATION feature x0028 MRW for 2.4.27 to support
> CDC_RAM. We only need that for MRW.
If you send me a patch, I'll be sure to review it. I won't be adding MRW
in 2.4. I made a substantial amount of changes and bug fixes while
migrating the code to 2.6, and I don't want to spend time on porting
that back to 2.4.
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-04-16 12:09 ` Jens Axboe
@ 2004-04-23 22:25 ` John McKell
2004-04-28 1:46 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: John McKell @ 2004-04-23 22:25 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pat LaVarre, linux-scsi
On Fri, 2004-04-16 at 06:09, Jens Axboe wrote:
> On Thu, Apr 15 2004, Pat LaVarre wrote:
> > Jens A:
> >
> > Would you consider for 2.4.27, a patch written to give us CDC_RAM alone?
> >
> > I ask because I notice, we don't need the problematic op x46
> > GPCMD_GET_CONFIGURATION feature x0028 MRW for 2.4.27 to support
> > CDC_RAM. We only need that for MRW.
>
> If you send me a patch, I'll be sure to review it. I won't be adding MRW
> in 2.4. I made a substantial amount of changes and bug fixes while
> migrating the code to 2.6, and I don't want to spend time on porting
> that back to 2.4.
Jens,
I have created a patch for 2.4.26 based on elements of your MRW patch for
2.6 as well as the patch we submitted to you for our device. Note that I
have taken out the MRW support and other changes that did not relate to
what we needed. Let us know what you think.
---John McKell
diff -Nurp linux-2.4.26/include/linux/cdrom.h linux/include/linux/cdrom.h
--- linux-2.4.26/include/linux/cdrom.h 2001-11-22 12:47:04.000000000 -0700
+++ linux/include/linux/cdrom.h 2004-04-22 16:14:03.000000000 -0600
@@ -5,7 +5,8 @@
* 1994, 1995 Eberhard Moenkeberg, emoenke@gwdg.de
* 1996 David van Leeuwen, david@tm.tno.nl
* 1997, 1998 Erik Andersen, andersee@debian.org
- * 1998-2000 Jens Axboe, axboe@suse.de
+ * 1998-2004 Jens Axboe, axboe@suse.de
+ * 2004 Iomega Corp
*/
#ifndef _LINUX_CDROM_H
@@ -387,6 +388,7 @@ struct cdrom_generic_command
#define CDC_DVD 0x8000 /* drive is a DVD */
#define CDC_DVD_R 0x10000 /* drive can write DVD-R */
#define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
+#define CDC_RAM 0x100000 /* ok to open WRITE */
/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
#define CDS_NO_INFO 0 /* if not implemented */
@@ -714,16 +716,43 @@ struct request_sense {
__u8 asb[46];
};
-#ifdef __KERNEL__
-#include <linux/devfs_fs_kernel.h>
+/*
+ * feature profile
+ */
+#define CDF_RWRT 0x0020
+#define CDF_HWDM 0x0024
-struct cdrom_write_settings {
- unsigned char fpacket; /* fixed/variable packets */
- unsigned long packet_size; /* write out this number of packets */
- unsigned long nwa; /* next writeable address */
- unsigned char writeable; /* cdrom is writeable */
+/* 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;
};
+#ifdef __KERNEL__
+#include <linux/devfs_fs_kernel.h>
+
/* Uniform cdrom data structures for cdrom.c */
struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */
@@ -744,7 +773,6 @@ struct cdrom_device_info {
/* per-device flags */
__u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
__u8 reserved : 6; /* not used yet */
- struct cdrom_write_settings write;
};
struct cdrom_device_ops {
@@ -1053,6 +1081,17 @@ typedef struct {
__u8 reserved3;
} rpc_state_t;
-#endif /* End of kernel only stuff */
+struct feature_header {
+ __u32 data_len;
+ __u8 reserved1;
+ __u8 reserved2;
+ __u16 curr_profile;
+};
+
+extern int cdrom_get_disc_info(kdev_t dev, disc_information *di);
+extern int cdrom_get_track_info(kdev_t dev, __u16 track, __u8 type,
+ track_information *ti);
+extern int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write);
+#endif /* __KERNEL__ */
#endif /* _LINUX_CDROM_H */
diff -Nurp linux-2.4.26/drivers/ide/ide-cd.h linux/drivers/ide/ide-cd.h
--- linux-2.4.26/drivers/ide/ide-cd.h 2003-06-13 08:51:33.000000000 -0600
+++ linux/drivers/ide/ide-cd.h 2004-04-22 16:14:34.000000000 -0600
@@ -2,7 +2,8 @@
* linux/drivers/ide/ide_cd.h
*
* Copyright (C) 1996-98 Erik Andersen
- * Copyright (C) 1998-2000 Jens Axboe
+ * Copyright (C) 1998-2004 Jens Axboe
+ * Copyright (C) 2004 Iomega Corp
*/
#ifndef _IDE_CD_H
#define _IDE_CD_H
@@ -75,6 +76,7 @@ struct ide_cd_config_flags {
__u8 dvd : 1; /* Drive is a DVD-ROM */
__u8 dvd_r : 1; /* Drive can write DVD-R */
__u8 dvd_ram : 1; /* Drive can write DVD-RAM */
+ __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */
__u8 test_write : 1; /* Drive can fake writes */
__u8 supp_disc_present : 1; /* Changer can report exact contents
of slots. */
diff -Nurp linux-2.4.26/drivers/ide/ide-cd.c linux/drivers/ide/ide-cd.c
--- linux-2.4.26/drivers/ide/ide-cd.c 2003-11-28 11:26:20.000000000 -0700
+++ linux/drivers/ide/ide-cd.c 2004-04-23 12:07:29.000000000 -0600
@@ -3,7 +3,8 @@
*
* Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov>
* Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
- * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 1998-2004 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 2004 Iomega Corp
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
@@ -2683,7 +2684,7 @@ static struct cdrom_device_ops ide_cdrom
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_GENERIC_PACKET | CDC_RAM,
generic_packet: ide_cdrom_packet,
};
@@ -2718,6 +2719,8 @@ static int ide_cdrom_register (ide_drive
devinfo->mask |= CDC_PLAY_AUDIO;
if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
devinfo->mask |= CDC_CLOSE_TRAY;
+ if (!CDROM_CONFIG_FLAGS(drive)->ram)
+ devinfo->mask |= CDC_RAM;
devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
@@ -2766,7 +2769,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 (CDROM_CONFIG_FLAGS(drive)->nec260) {
CDROM_CONFIG_FLAGS(drive)->no_eject = 0;
@@ -2776,7 +2779,9 @@ int ide_cdrom_probe_capabilities (ide_dr
if (ide_cdrom_get_capabilities(drive, &cap))
return 0;
-
+ 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)
@@ -2789,8 +2794,10 @@ int ide_cdrom_probe_capabilities (ide_dr
CDROM_CONFIG_FLAGS(drive)->test_write = 1;
if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
CDROM_CONFIG_FLAGS(drive)->dvd = 1;
- if (cap.dvd_ram_write)
+ if (cap.dvd_ram_write) {
CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1;
+ CDROM_CONFIG_FLAGS(drive)->ram = 1;
+ }
if (cap.dvd_r_write)
CDROM_CONFIG_FLAGS(drive)->dvd_r = 1;
if (cap.audio_play)
@@ -3000,7 +3007,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
nslots = ide_cdrom_probe_capabilities (drive);
- if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
+ if ((CDROM_CONFIG_FLAGS(drive)->dvd_ram) ||
+ (CDROM_CONFIG_FLAGS(drive)->ram))
set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
#if 0
diff -Nurp linux-2.4.26/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- linux-2.4.26/drivers/scsi/sr.c 2003-06-13 08:51:36.000000000 -0600
+++ linux/drivers/scsi/sr.c 2004-04-22 16:15:39.000000000 -0600
@@ -1,6 +1,7 @@
/*
* sr.c Copyright (C) 1992 David Giller
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
+ * Copyright (C) 2004 Iomega Corp
*
* adapted from:
* sd.c Copyright (C) 1992 Drew Eckhardt
@@ -128,7 +129,7 @@ static struct cdrom_device_ops sr_dops =
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_DVD_RAM | CDC_GENERIC_PACKET | CDC_RAM,
generic_packet: sr_packet,
};
@@ -693,7 +694,7 @@ void get_capabilities(int i)
{
unsigned char cmd[6];
unsigned char *buffer;
- int rc, n;
+ int rc, n, ram_write=0;
static char *loadmech[] =
{
@@ -731,6 +732,11 @@ void get_capabilities(int i)
printk("sr%i: scsi-1 drive\n", i);
return;
}
+ if (cdrom_is_random_writable(&scsi_CDs[i].cdi, &ram_write))
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+ if (!ram_write)
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+
n = buffer[3] + 4;
scsi_CDs[i].cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
scsi_CDs[i].readcd_known = 1;
@@ -754,8 +760,6 @@ void get_capabilities(int i)
if ((buffer[n + 3] & 0x20) == 0) {
/* can't write DVD-RAM media */
scsi_CDs[i].cdi.mask |= CDC_DVD_RAM;
- } else {
- scsi_CDs[i].device->writeable = 1;
}
if ((buffer[n + 3] & 0x10) == 0)
/* can't write DVD-R media */
@@ -780,6 +784,13 @@ void get_capabilities(int i)
/*else I don't think it can close its tray
scsi_CDs[i].cdi.mask |= CDC_CLOSE_TRAY; */
+ /*
+ * if DVD-RAM of MRW-W, we are randomly writeable
+ */
+ if ((scsi_CDs[i].cdi.mask & (CDC_DVD_RAM | CDC_RAM)) !=
+ (CDC_DVD_RAM | CDC_RAM))
+ scsi_CDs[i].device->writeable = 1;
+
scsi_free(buffer, 512);
}
diff -Nurp linux-2.4.26/drivers/cdrom/cdrom.c linux/drivers/cdrom/cdrom.c
--- linux-2.4.26/drivers/cdrom/cdrom.c 2003-11-28 11:26:20.000000000 -0700
+++ linux/drivers/cdrom/cdrom.c 2004-04-22 16:12:25.000000000 -0600
@@ -1,7 +1,8 @@
/* linux/drivers/cdrom/cdrom.c.
Copyright (c) 1996, 1997 David A. van Leeuwen.
Copyright (c) 1997, 1998 Erik Andersen <andersee@debian.org>
- Copyright (c) 1998, 1999 Jens Axboe <axboe@image.dk>
+ Copyright (c) 1998-2004 Jens Axboe <axboe@image.dk>
+ Copyright (c) 2004, Iomega Corp.
May be copied or modified under the terms of the GNU General Public
License. See linux/COPYING for more information.
@@ -447,6 +448,112 @@ struct cdrom_device_info *cdrom_find_dev
return cdi;
}
+int cdrom_get_random_writable(struct cdrom_device_info *cdi,
+ struct rwrt_feature_desc *rfd)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[24];
+ struct feature_header *fh;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_RWRT; /* often 0x0020 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x18 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+
+ sizeof(struct rwrt_feature_desc)))
+ memcpy(rfd, &buffer[sizeof(struct feature_header)],
+ sizeof (*rfd));
+ else
+ memset(rfd, 0, sizeof(*rfd));
+
+ return 0;
+}
+
+int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[16];
+ struct feature_header *fh;
+ __u16 *feature_code;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_HWDM; /* often 0x0024 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x10 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ ret = 1;
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+8)) {
+ feature_code = (__u16 *)&buffer[sizeof(struct feature_header)];
+ if (CDF_HWDM == be16_to_cpu(*feature_code))
+ ret = 0;
+ }
+ return ret;
+}
+
+
+int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ *write = 0;
+
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+
+ if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ *write = 1;
+
+ return 0;
+}
+
+static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ if ((ret = cdrom_has_defect_mgt(cdi)))
+ return ret;
+ else
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+ else if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ ret = !rfd.curr;
+
+ cdinfo(CD_OPEN, "can open for random write\n");
+ return ret;
+}
+
+/*
+ * returns 0 for ok to open write, non-0 to disallow
+ */
+static int cdrom_open_write(struct cdrom_device_info *cdi)
+{
+ int ret;
+ if (CDROM_CAN(CDC_RAM) &&
+ !CDROM_CAN(CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R))
+ ret = cdrom_ram_open_write(cdi);
+ else
+ ret = 1;
+
+ return ret;
+}
+
/* We use the open-option O_NONBLOCK to indicate that the
* purpose of opening is only for subsequent ioctl() calls; no device
* integrity checks are performed.
@@ -465,8 +572,15 @@ int cdrom_open(struct inode *ip, struct
if ((cdi = cdrom_find_device(dev)) == NULL)
return -ENODEV;
- if ((fp->f_mode & FMODE_WRITE) && !CDROM_CAN(CDC_DVD_RAM))
- return -EROFS;
+ cdi->use_count++;
+ ret = -EROFS;
+ if (fp->f_mode & FMODE_WRITE) {
+ printk("cdrom: %s opening for WRITE\n", current->comm);
+ if (!CDROM_CAN(CDC_RAM))
+ goto out;
+ if (cdrom_open_write(cdi))
+ goto out;
+ }
/* if this was a O_NONBLOCK open and we should honor the flags,
* do a quick open without drive/disc integrity checks. */
@@ -475,12 +589,13 @@ int cdrom_open(struct inode *ip, struct
else
ret = open_for_data(cdi);
- if (!ret) cdi->use_count++;
-
cdinfo(CD_OPEN, "Use count for \"/dev/%s\" now %d\n", cdi->name, cdi->use_count);
/* Do this on open. Don't wait for mount, because they might
not be mounting, but opening with O_NONBLOCK */
check_disk_change(dev);
+out:
+ if (ret)
+ cdi->use_count--;
return ret;
}
@@ -657,15 +772,14 @@ int cdrom_release(struct inode *ip, stru
cdinfo(CD_CLOSE, "entering cdrom_release\n");
- if (cdi->use_count > 0)
- cdi->use_count--;
- if (cdi->use_count == 0)
+ if (!--cdi->use_count) {
cdinfo(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n", cdi->name);
- if (cdi->use_count == 0 &&
- cdo->capability & CDC_LOCK && !keeplocked) {
- cdinfo(CD_CLOSE, "Unlocking door!\n");
- cdo->lock_door(cdi, 0);
+ if ((cdo->capability & CDC_LOCK) && !keeplocked) {
+ cdinfo(CD_CLOSE, "Unlocking door!\n");
+ cdo->lock_door(cdi, 0);
+ }
}
+
opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
!(fp && fp->f_flags & O_NONBLOCK);
cdo->release(cdi);
@@ -1909,10 +2023,24 @@ static int cdrom_do_cmd(struct cdrom_dev
}
}
+ /*
+ * queue command and wait for it to complete
+ */
ret = cdi->ops->generic_packet(cdi, cgc);
- __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * always copy back sense, command need not have failed for it to
+ * contain useful info
+ */
+ if (usense)
+ __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * this really needs to be modified to copy back good bytes
+ */
if (!ret && cgc->data_direction == CGC_DATA_READ)
__copy_to_user(ubuf, cgc->buffer, cgc->buflen);
+
if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
kfree(cgc->buffer);
@@ -2392,6 +2520,7 @@ EXPORT_SYMBOL(cdrom_mode_select);
EXPORT_SYMBOL(cdrom_mode_sense);
EXPORT_SYMBOL(init_cdrom_command);
EXPORT_SYMBOL(cdrom_find_device);
+EXPORT_SYMBOL(cdrom_is_random_writable);
#ifdef CONFIG_SYSCTL
@@ -2488,6 +2617,10 @@ int cdrom_sysctl_info(ctl_table *ctl, in
for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_DVD_RAM) != 0);
+ pos += sprintf(info+pos, "\nCan write RAM:\t");
+ for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
+ pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_RAM) != 0);
+
strcpy(info+pos,"\n\n");
return proc_dostring(ctl, write, filp, buffer, lenp);
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-04-23 22:25 ` John McKell
@ 2004-04-28 1:46 ` Pat LaVarre
2004-04-28 14:48 ` Pat LaVarre
[not found] ` <1084897080.3746.38.camel@patibmrh9>
0 siblings, 2 replies; 20+ messages in thread
From: Pat LaVarre @ 2004-04-28 1:46 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
Jens A:
> http://marc.theaimsgroup.com/?l=linux-scsi&m=108275922808836&q=raw
In answer to your short silence, I now take the liberty of
retransmitting this patch. Specifically I have reason to fear that the
copy you received previously may have violated our taboo against Html in
e-mail.
We apply this patch to make "feature" x0020 "Random Writable" plus
feature x0024 "Hardware Defect Management" mean CDC_RAM "ok to open for
WRITE". However, by contrast with 2.6.2, we omit the aggressive CD-MRW
probing, for the sake of 2.4 stability.
In this retransmission, I grew the #define CDF comments to match 2.6.5.
Between first and re- transmission, I confirmed 2.4.27-pre1 swallows
this patch without complaint, as did 2.4.26, and I saw this patch made
USB write CDC_RAM discs.
I look forward to your review.
Pat LaVarre
http://sourceforge.net/projects/iomrrdtools/
P.S. I now emphasise, though pending your instruction I have not
deleted, the per-open dmesg that this 2.4 patch introduces that 2.6.5
lacks:
int cdrom_open(struct inode *ip, struct
...
ret = -EROFS;
if (fp->f_mode & FMODE_WRITE) {
printk("cdrom: %s opening for WRITE\n", current->comm);
diff -Nurp linux-2.4.26/include/linux/cdrom.h linux/include/linux/cdrom.h
--- linux-2.4.26/include/linux/cdrom.h 2001-11-22 12:47:04.000000000 -0700
+++ linux/include/linux/cdrom.h 2004-04-22 16:14:03.000000000 -0600
@@ -5,7 +5,8 @@
* 1994, 1995 Eberhard Moenkeberg, emoenke@gwdg.de
* 1996 David van Leeuwen, david@tm.tno.nl
* 1997, 1998 Erik Andersen, andersee@debian.org
- * 1998-2000 Jens Axboe, axboe@suse.de
+ * 1998-2004 Jens Axboe, axboe@suse.de
+ * 2004 Iomega Corp
*/
#ifndef _LINUX_CDROM_H
@@ -387,6 +388,7 @@ struct cdrom_generic_command
#define CDC_DVD 0x8000 /* drive is a DVD */
#define CDC_DVD_R 0x10000 /* drive can write DVD-R */
#define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
+#define CDC_RAM 0x100000 /* ok to open WRITE */
/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
#define CDS_NO_INFO 0 /* if not implemented */
@@ -714,16 +716,43 @@ struct request_sense {
__u8 asb[46];
};
-#ifdef __KERNEL__
-#include <linux/devfs_fs_kernel.h>
+/*
+ * feature profile
+ */
+#define CDF_RWRT 0x0020 /* "Random Writable" */
+#define CDF_HWDM 0x0024 /* "Hardware Defect Management" */
-struct cdrom_write_settings {
- unsigned char fpacket; /* fixed/variable packets */
- unsigned long packet_size; /* write out this number of packets */
- unsigned long nwa; /* next writeable address */
- unsigned char writeable; /* cdrom is writeable */
+/* 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;
};
+#ifdef __KERNEL__
+#include <linux/devfs_fs_kernel.h>
+
/* Uniform cdrom data structures for cdrom.c */
struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */
@@ -744,7 +773,6 @@ struct cdrom_device_info {
/* per-device flags */
__u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
__u8 reserved : 6; /* not used yet */
- struct cdrom_write_settings write;
};
struct cdrom_device_ops {
@@ -1053,6 +1081,17 @@ typedef struct {
__u8 reserved3;
} rpc_state_t;
-#endif /* End of kernel only stuff */
+struct feature_header {
+ __u32 data_len;
+ __u8 reserved1;
+ __u8 reserved2;
+ __u16 curr_profile;
+};
+
+extern int cdrom_get_disc_info(kdev_t dev, disc_information *di);
+extern int cdrom_get_track_info(kdev_t dev, __u16 track, __u8 type,
+ track_information *ti);
+extern int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write);
+#endif /* __KERNEL__ */
#endif /* _LINUX_CDROM_H */
diff -Nurp linux-2.4.26/drivers/ide/ide-cd.h linux/drivers/ide/ide-cd.h
--- linux-2.4.26/drivers/ide/ide-cd.h 2003-06-13 08:51:33.000000000 -0600
+++ linux/drivers/ide/ide-cd.h 2004-04-22 16:14:34.000000000 -0600
@@ -2,7 +2,8 @@
* linux/drivers/ide/ide_cd.h
*
* Copyright (C) 1996-98 Erik Andersen
- * Copyright (C) 1998-2000 Jens Axboe
+ * Copyright (C) 1998-2004 Jens Axboe
+ * Copyright (C) 2004 Iomega Corp
*/
#ifndef _IDE_CD_H
#define _IDE_CD_H
@@ -75,6 +76,7 @@ struct ide_cd_config_flags {
__u8 dvd : 1; /* Drive is a DVD-ROM */
__u8 dvd_r : 1; /* Drive can write DVD-R */
__u8 dvd_ram : 1; /* Drive can write DVD-RAM */
+ __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */
__u8 test_write : 1; /* Drive can fake writes */
__u8 supp_disc_present : 1; /* Changer can report exact contents
of slots. */
diff -Nurp linux-2.4.26/drivers/ide/ide-cd.c linux/drivers/ide/ide-cd.c
--- linux-2.4.26/drivers/ide/ide-cd.c 2003-11-28 11:26:20.000000000 -0700
+++ linux/drivers/ide/ide-cd.c 2004-04-23 12:07:29.000000000 -0600
@@ -3,7 +3,8 @@
*
* Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov>
* Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
- * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 1998-2004 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 2004 Iomega Corp
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
@@ -2683,7 +2684,7 @@ static struct cdrom_device_ops ide_cdrom
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_GENERIC_PACKET | CDC_RAM,
generic_packet: ide_cdrom_packet,
};
@@ -2718,6 +2719,8 @@ static int ide_cdrom_register (ide_drive
devinfo->mask |= CDC_PLAY_AUDIO;
if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
devinfo->mask |= CDC_CLOSE_TRAY;
+ if (!CDROM_CONFIG_FLAGS(drive)->ram)
+ devinfo->mask |= CDC_RAM;
devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
@@ -2766,7 +2769,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 (CDROM_CONFIG_FLAGS(drive)->nec260) {
CDROM_CONFIG_FLAGS(drive)->no_eject = 0;
@@ -2776,7 +2779,9 @@ int ide_cdrom_probe_capabilities (ide_dr
if (ide_cdrom_get_capabilities(drive, &cap))
return 0;
-
+ 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)
@@ -2789,8 +2794,10 @@ int ide_cdrom_probe_capabilities (ide_dr
CDROM_CONFIG_FLAGS(drive)->test_write = 1;
if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
CDROM_CONFIG_FLAGS(drive)->dvd = 1;
- if (cap.dvd_ram_write)
+ if (cap.dvd_ram_write) {
CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1;
+ CDROM_CONFIG_FLAGS(drive)->ram = 1;
+ }
if (cap.dvd_r_write)
CDROM_CONFIG_FLAGS(drive)->dvd_r = 1;
if (cap.audio_play)
@@ -3000,7 +3007,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
nslots = ide_cdrom_probe_capabilities (drive);
- if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
+ if ((CDROM_CONFIG_FLAGS(drive)->dvd_ram) ||
+ (CDROM_CONFIG_FLAGS(drive)->ram))
set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
#if 0
diff -Nurp linux-2.4.26/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- linux-2.4.26/drivers/scsi/sr.c 2003-06-13 08:51:36.000000000 -0600
+++ linux/drivers/scsi/sr.c 2004-04-22 16:15:39.000000000 -0600
@@ -1,6 +1,7 @@
/*
* sr.c Copyright (C) 1992 David Giller
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
+ * Copyright (C) 2004 Iomega Corp
*
* adapted from:
* sd.c Copyright (C) 1992 Drew Eckhardt
@@ -128,7 +129,7 @@ static struct cdrom_device_ops sr_dops =
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_DVD_RAM | CDC_GENERIC_PACKET | CDC_RAM,
generic_packet: sr_packet,
};
@@ -693,7 +694,7 @@ void get_capabilities(int i)
{
unsigned char cmd[6];
unsigned char *buffer;
- int rc, n;
+ int rc, n, ram_write=0;
static char *loadmech[] =
{
@@ -731,6 +732,11 @@ void get_capabilities(int i)
printk("sr%i: scsi-1 drive\n", i);
return;
}
+ if (cdrom_is_random_writable(&scsi_CDs[i].cdi, &ram_write))
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+ if (!ram_write)
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+
n = buffer[3] + 4;
scsi_CDs[i].cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
scsi_CDs[i].readcd_known = 1;
@@ -754,8 +760,6 @@ void get_capabilities(int i)
if ((buffer[n + 3] & 0x20) == 0) {
/* can't write DVD-RAM media */
scsi_CDs[i].cdi.mask |= CDC_DVD_RAM;
- } else {
- scsi_CDs[i].device->writeable = 1;
}
if ((buffer[n + 3] & 0x10) == 0)
/* can't write DVD-R media */
@@ -780,6 +784,13 @@ void get_capabilities(int i)
/*else I don't think it can close its tray
scsi_CDs[i].cdi.mask |= CDC_CLOSE_TRAY; */
+ /*
+ * if DVD-RAM of MRW-W, we are randomly writeable
+ */
+ if ((scsi_CDs[i].cdi.mask & (CDC_DVD_RAM | CDC_RAM)) !=
+ (CDC_DVD_RAM | CDC_RAM))
+ scsi_CDs[i].device->writeable = 1;
+
scsi_free(buffer, 512);
}
diff -Nurp linux-2.4.26/drivers/cdrom/cdrom.c linux/drivers/cdrom/cdrom.c
--- linux-2.4.26/drivers/cdrom/cdrom.c 2003-11-28 11:26:20.000000000 -0700
+++ linux/drivers/cdrom/cdrom.c 2004-04-22 16:12:25.000000000 -0600
@@ -1,7 +1,8 @@
/* linux/drivers/cdrom/cdrom.c.
Copyright (c) 1996, 1997 David A. van Leeuwen.
Copyright (c) 1997, 1998 Erik Andersen <andersee@debian.org>
- Copyright (c) 1998, 1999 Jens Axboe <axboe@image.dk>
+ Copyright (c) 1998-2004 Jens Axboe <axboe@image.dk>
+ Copyright (c) 2004, Iomega Corp.
May be copied or modified under the terms of the GNU General Public
License. See linux/COPYING for more information.
@@ -447,6 +448,112 @@ struct cdrom_device_info *cdrom_find_dev
return cdi;
}
+int cdrom_get_random_writable(struct cdrom_device_info *cdi,
+ struct rwrt_feature_desc *rfd)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[24];
+ struct feature_header *fh;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_RWRT; /* often 0x0020 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x18 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+
+ sizeof(struct rwrt_feature_desc)))
+ memcpy(rfd, &buffer[sizeof(struct feature_header)],
+ sizeof (*rfd));
+ else
+ memset(rfd, 0, sizeof(*rfd));
+
+ return 0;
+}
+
+int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[16];
+ struct feature_header *fh;
+ __u16 *feature_code;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_HWDM; /* often 0x0024 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x10 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ ret = 1;
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+8)) {
+ feature_code = (__u16 *)&buffer[sizeof(struct feature_header)];
+ if (CDF_HWDM == be16_to_cpu(*feature_code))
+ ret = 0;
+ }
+ return ret;
+}
+
+
+int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ *write = 0;
+
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+
+ if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ *write = 1;
+
+ return 0;
+}
+
+static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ if ((ret = cdrom_has_defect_mgt(cdi)))
+ return ret;
+ else
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+ else if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ ret = !rfd.curr;
+
+ cdinfo(CD_OPEN, "can open for random write\n");
+ return ret;
+}
+
+/*
+ * returns 0 for ok to open write, non-0 to disallow
+ */
+static int cdrom_open_write(struct cdrom_device_info *cdi)
+{
+ int ret;
+ if (CDROM_CAN(CDC_RAM) &&
+ !CDROM_CAN(CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R))
+ ret = cdrom_ram_open_write(cdi);
+ else
+ ret = 1;
+
+ return ret;
+}
+
/* We use the open-option O_NONBLOCK to indicate that the
* purpose of opening is only for subsequent ioctl() calls; no device
* integrity checks are performed.
@@ -465,8 +572,15 @@ int cdrom_open(struct inode *ip, struct
if ((cdi = cdrom_find_device(dev)) == NULL)
return -ENODEV;
- if ((fp->f_mode & FMODE_WRITE) && !CDROM_CAN(CDC_DVD_RAM))
- return -EROFS;
+ cdi->use_count++;
+ ret = -EROFS;
+ if (fp->f_mode & FMODE_WRITE) {
+ printk("cdrom: %s opening for WRITE\n", current->comm);
+ if (!CDROM_CAN(CDC_RAM))
+ goto out;
+ if (cdrom_open_write(cdi))
+ goto out;
+ }
/* if this was a O_NONBLOCK open and we should honor the flags,
* do a quick open without drive/disc integrity checks. */
@@ -475,12 +589,13 @@ int cdrom_open(struct inode *ip, struct
else
ret = open_for_data(cdi);
- if (!ret) cdi->use_count++;
-
cdinfo(CD_OPEN, "Use count for \"/dev/%s\" now %d\n", cdi->name, cdi->use_count);
/* Do this on open. Don't wait for mount, because they might
not be mounting, but opening with O_NONBLOCK */
check_disk_change(dev);
+out:
+ if (ret)
+ cdi->use_count--;
return ret;
}
@@ -657,15 +772,14 @@ int cdrom_release(struct inode *ip, stru
cdinfo(CD_CLOSE, "entering cdrom_release\n");
- if (cdi->use_count > 0)
- cdi->use_count--;
- if (cdi->use_count == 0)
+ if (!--cdi->use_count) {
cdinfo(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n", cdi->name);
- if (cdi->use_count == 0 &&
- cdo->capability & CDC_LOCK && !keeplocked) {
- cdinfo(CD_CLOSE, "Unlocking door!\n");
- cdo->lock_door(cdi, 0);
+ if ((cdo->capability & CDC_LOCK) && !keeplocked) {
+ cdinfo(CD_CLOSE, "Unlocking door!\n");
+ cdo->lock_door(cdi, 0);
+ }
}
+
opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
!(fp && fp->f_flags & O_NONBLOCK);
cdo->release(cdi);
@@ -1909,10 +2023,24 @@ static int cdrom_do_cmd(struct cdrom_dev
}
}
+ /*
+ * queue command and wait for it to complete
+ */
ret = cdi->ops->generic_packet(cdi, cgc);
- __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * always copy back sense, command need not have failed for it to
+ * contain useful info
+ */
+ if (usense)
+ __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * this really needs to be modified to copy back good bytes
+ */
if (!ret && cgc->data_direction == CGC_DATA_READ)
__copy_to_user(ubuf, cgc->buffer, cgc->buflen);
+
if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
kfree(cgc->buffer);
@@ -2392,6 +2520,7 @@ EXPORT_SYMBOL(cdrom_mode_select);
EXPORT_SYMBOL(cdrom_mode_sense);
EXPORT_SYMBOL(init_cdrom_command);
EXPORT_SYMBOL(cdrom_find_device);
+EXPORT_SYMBOL(cdrom_is_random_writable);
#ifdef CONFIG_SYSCTL
@@ -2488,6 +2617,10 @@ int cdrom_sysctl_info(ctl_table *ctl, in
for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_DVD_RAM) != 0);
+ pos += sprintf(info+pos, "\nCan write RAM:\t");
+ for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
+ pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_RAM) != 0);
+
strcpy(info+pos,"\n\n");
return proc_dostring(ctl, write, filp, buffer, lenp);
-
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-04-28 1:46 ` Pat LaVarre
@ 2004-04-28 14:48 ` Pat LaVarre
[not found] ` <1084897080.3746.38.camel@patibmrh9>
1 sibling, 0 replies; 20+ messages in thread
From: Pat LaVarre @ 2004-04-28 14:48 UTC (permalink / raw)
To: linux-scsi
> Specifically I have reason to fear that the
> copy you received previously may have violated
> our taboo against Html in e-mail.
Sorry to say I now have evidence of Html in both posts of this thread
that arrived after Jens last spoke. Unless someone else acts, I won't
soon have a way to know whether Jens has received an html-free copy or
not, though I do see an html-free copy archived at:
http://marc.theaimsgroup.com/?l=linux-scsi&m=108311702301193&q=raw
Pat LaVarre
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
[not found] ` <1084897080.3746.38.camel@patibmrh9>
@ 2004-05-19 8:15 ` Jens Axboe
2004-05-19 15:45 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-05-19 8:15 UTC (permalink / raw)
To: Pat LaVarre; +Cc: linux-scsi, John McKell
On Tue, May 18 2004, Pat LaVarre wrote:
> In the absence of a consensus over a more elegant resolution, I'm
> getting by for now with the following, dramatically concise,
> alternative.
>
> Pat LaVarre
>
> ----- Forwarded Message -----
> ...
>
> grep in the rewritable-patch-0.3b/rewrite-2.4.26.patch of
> http://sourceforge.net/projects/iomrrdtools/ reminds me the source files
> at issue are:
>
> include/linux/cdrom.h
> drivers/ide/ide-cd.h
> drivers/ide/ide-cd.c
> drivers/scsi/sr.c
> drivers/cdrom/cdrom.c
>
> The following two file patch gives me the result:
>
> $ sudo rrd scan
> /dev/scd0 is Iomega RRD 74.B rw
> /dev/hdc 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/hdc bs=64K count=1 if=/dev/zero
> 1+0 records in
> 1+0 records out
> $
>
> rather than the kernel.org 2.4.18 default:
>
> $ sudo rrd scan
> /dev/scd0 is Iomega RRD 74.B rw
> /dev/hdc is Iomega RRD 74.B rw
> $
> $ sudo dd of=/dev/scd0 bs=64K skip=0 count=1 if=/dev/zero
> dd: opening `/dev/scd0': Read-only file system
> $
> $ sudo dd of=/dev/hdc bs=64K skip=0 count=1 if=/dev/zero
> dd: opening `/dev/hdc': Read-only file system
> $
>
> Pat LaVarre
>
> diff -Nurp linux-2.4.18/include/linux/cdrom.h linux-2.4.18-pel/include/linux/cdrom.h
> diff -Nurp linux-2.4.18/drivers/ide/ide-cd.h linux-2.4.18-pel/drivers/ide/ide-cd.h
> diff -Nurp linux-2.4.18/drivers/ide/ide-cd.c linux-2.4.18-pel/drivers/ide/ide-cd.c
> --- linux-2.4.18/drivers/ide/ide-cd.c 2002-02-25 12:37:57.000000000 -0700
> +++ linux-2.4.18-pel/drivers/ide/ide-cd.c 2004-05-18 08:55:14.000000000 -0600
> @@ -2599,6 +2599,13 @@ int ide_cdrom_get_capabilities(ide_drive
> if (!stat)
> break;
> } while (--attempts);
> +#if 1 /* see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible */
> + if (!stat) {
> + cap->dvd_rom = 1;
> + cap->dvd_ram_read = 1;
> + cap->dvd_ram_write = 1;
> + }
> +#endif
> return stat;
> }
This looks incredibly odd - if we succeed in getting the mode sense
capabilities page, you force setting og dvd-rom/ram?!
> diff -Nurp linux-2.4.18/drivers/scsi/sr.c linux-2.4.18-pel/drivers/scsi/sr.c
> --- linux-2.4.18/drivers/scsi/sr.c 2002-02-25 12:38:04.000000000 -0700
> +++ linux-2.4.18-pel/drivers/scsi/sr.c 2004-05-18 08:55:53.000000000 -0600
> @@ -709,6 +709,10 @@ void get_capabilities(int i)
> return;
> }
> n = buffer[3] + 4;
> +#if 1 /* see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible */
> + buffer[n + 2] |= 0x28; /* readable: x20 = DVD-RAM, x08 = DVD-ROM */
> + buffer[n + 3] |= 0x20; /* writable: x20 = DVD-RAM */
> +#endif
> scsi_CDs[i].cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
> scsi_CDs[i].readcd_known = 1;
> scsi_CDs[i].readcd_cdda = buffer[n + 5] & 0x01;
> diff -Nurp linux-2.4.18/drivers/cdrom/cdrom.c linux-2.4.18-pel/drivers/cdrom/cdrom.c
Ditto here. Please explain your reasoning for this patch. And do base
patches on recent kernels please, 2.4.18 is over 2 years old.
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-19 8:15 ` Jens Axboe
@ 2004-05-19 15:45 ` Pat LaVarre
2004-05-20 8:06 ` Jens Axboe
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-05-19 15:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
Jens A:
> Please explain your reasoning for this patch.
I fear to answer fully, because I see I have a history of answering in
ways that make you lose interest.
I see you have not yet volunteered to review the 2.4.26 patch proposed
in this thread 2004-04-23 by John McKell, written to give us CDC_RAM
alone without MRW in 2.4.
Can I help best by updating that patch to become a 2.4.27-pre3 patch?
Pat LaVarre
----- ----- -----
P.S. An alternative, less short reply that I also drafted was:
> > linux-2.4.18/drivers/ide/ide-cd.c
> if we succeed in getting the mode sense capabilities page,
> you force setting og dvd-rom/ram?!
> ...
> > linux-2.4.18/drivers/scsi/sr.c
> Ditto here.
Yes.
I believe 2.4.18 patch actually makes `mount -w` work there by way of
"see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible".
> Please explain your reasoning for this patch.
Sorry I don't understand what you don't understand.
You're clearly far more expert in this area of Linux than I.
I say my 2.4.18 patch works because otherwise cdrom/ ide-cd/ sr older
than 2.6.2 together decide to fail open via EROFS any time a DVD/ CD
drive reports it is mechanically incompatible with DVD-RAM, no matter
what kind of disc is actually inserted at the time.
You knew that already, yes?
How can I have been unclear?
> And do base patches on recent kernels please,
> 2.4.18 is over 2 years old.
Yes I fetch from kernel.org when I write for merge to kernel.org.
For example, my last linux-ide patch posted is against 2.6.6-bk5.
But this 2.4.18 linux-scsi patch I wrote to help when yet another person
offline was hurt by discovering that `mount -w` did not work for DVD/ CD
discs other than DVD-RAM without an upgrade to Linux-2.6.2 or newer.
I now have this patch archived as patches-be.dvd.ram of:
http://sourceforge.net/projects/iomrrdtools/
I expect in time I will rewrite this patch for 2.4.26, 2.4.25, ... and
back thru all the 2.4 now massively redistributed. The `mount -w` of
2.6.1 thru 2.6.5 also need this patch, but I hope to avoid writing it
there by insisting 2.6 people should begin life with 2.6.5 or better.
Pat LaVarre
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-19 15:45 ` Pat LaVarre
@ 2004-05-20 8:06 ` Jens Axboe
2004-05-20 22:01 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-05-20 8:06 UTC (permalink / raw)
To: Pat LaVarre; +Cc: linux-scsi, John McKell
On Wed, May 19 2004, Pat LaVarre wrote:
> Jens A:
>
> > Please explain your reasoning for this patch.
>
> I fear to answer fully, because I see I have a history of answering in
> ways that make you lose interest.
Sorry you feel that way. It's not loss of interesting, mainly juggling
other tasks.
> I see you have not yet volunteered to review the 2.4.26 patch proposed
> in this thread 2004-04-23 by John McKell, written to give us CDC_RAM
> alone without MRW in 2.4.
>
> Can I help best by updating that patch to become a 2.4.27-pre3 patch?
2.4.26 patch should apply to 2.4.27-pre3 as well, I think. But it
doesn't hurt to check.
> ----- ----- -----
>
> P.S. An alternative, less short reply that I also drafted was:
>
> > > linux-2.4.18/drivers/ide/ide-cd.c
> > if we succeed in getting the mode sense capabilities page,
> > you force setting og dvd-rom/ram?!
> > ...
> > > linux-2.4.18/drivers/scsi/sr.c
> > Ditto here.
>
> Yes.
>
> I believe 2.4.18 patch actually makes `mount -w` work there by way of
> "see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible".
But that's not what the patch does at all. The patch simply says "If we
succeeded in retriving the mode capability page, ignore what it says and
flag the drive as dvd-rom/ram capable" which is clearly bogus.
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-20 8:06 ` Jens Axboe
@ 2004-05-20 22:01 ` Pat LaVarre
2004-05-20 23:51 ` Pat LaVarre
2004-05-21 6:53 ` Jens Axboe
0 siblings, 2 replies; 20+ messages in thread
From: Pat LaVarre @ 2004-05-20 22:01 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
Jens A:
> 2.4.26 patch should apply to 2.4.27-pre3 as well, I think.
> But it doesn't hurt to check.
In short:
Yes, it applies.
> 2.4.26 patch should apply to 2.4.27-pre3 as well, I think.
> But it doesn't hurt to check.
At length ...
John McKell's 2.4.26 patch still applies clean. I see:
$ cd linux-2.4.27-pre3/
$ patch --dry-run -p1 <http://marc.theaimsgroup.com/?l=linux-scsi&m=...
patching file include/linux/cdrom.h
patching file drivers/ide/ide-cd.h
patching file drivers/ide/ide-cd.c
patching file drivers/scsi/sr.c
patching file drivers/cdrom/cdrom.c
$
Also I include a copy inline below for your convenience.
Also I will install & reboot & look for trouble.
diff confirms for me the patch inline of this post matches what John
McKell posted, except for the trivial difference of folder names & dates
and the substantive difference that I did comment out the per-open
printk:
- + printk("cdrom: %s opening for WRITE\n", current->comm);
+ + /* printk("cdrom: %s opening for WRITE\n", current->comm); */
> > I fear to answer fully, because I see I have a history of answering in
> > ways that make you lose interest.
>
> Sorry you feel that way. It's not loss of interesting, mainly juggling
> other tasks.
Thanks for finding the time to correct my interpretation.
Sorry I did not understand.
I see you volunteering, I'm trying to discover how I the newbie can help
more than I hurt.
> > I believe 2.4.18 patch actually makes `mount -w` work there by way of
> > "see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible".
>
> But that's not what the patch does at all. The patch simply says "If we
> succeeded in retriving the mode capability page, ignore what it says and
> flag the drive as dvd-rom/ram capable" which is clearly bogus.
To newbie me, this is not clearly bogus, sorry.
1)
I see my 2.4.18 patch makes `mount -w` work, by way of breaking `cat
/proc/sys/dev/cdrom/info`.
mount matters more to me than proc.
Besides, the breakage is small. I'm not falsely claiming that a DVD-RAM
disc is present. I'm only falsely claiming that a DVD-RAM disc could be
present. Software that branches visibly on which kind of disc might
someday be present looks very nearly bogus to me.
2)
I see my 2.4.18 patch is extremely short and simple.
Simplicity in the patch matters more to me the further I step back from
the latest available at kernel.org.
Pat LaVarre
diff -Nurp linux-2.4.27-pre3/include/linux/cdrom.h linux-2.4.27-pre3-pel/include/linux/cdrom.h
--- linux-2.4.27-pre3/include/linux/cdrom.h 2001-11-22 12:47:04.000000000 -0700
+++ linux-2.4.27-pre3-pel/include/linux/cdrom.h 2004-05-20 15:39:26.573524352 -0600
@@ -5,7 +5,8 @@
* 1994, 1995 Eberhard Moenkeberg, emoenke@gwdg.de
* 1996 David van Leeuwen, david@tm.tno.nl
* 1997, 1998 Erik Andersen, andersee@debian.org
- * 1998-2000 Jens Axboe, axboe@suse.de
+ * 1998-2004 Jens Axboe, axboe@suse.de
+ * 2004 Iomega Corp
*/
#ifndef _LINUX_CDROM_H
@@ -387,6 +388,7 @@ struct cdrom_generic_command
#define CDC_DVD 0x8000 /* drive is a DVD */
#define CDC_DVD_R 0x10000 /* drive can write DVD-R */
#define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
+#define CDC_RAM 0x100000 /* ok to open WRITE */
/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
#define CDS_NO_INFO 0 /* if not implemented */
@@ -714,16 +716,43 @@ struct request_sense {
__u8 asb[46];
};
-#ifdef __KERNEL__
-#include <linux/devfs_fs_kernel.h>
+/*
+ * feature profile
+ */
+#define CDF_RWRT 0x0020
+#define CDF_HWDM 0x0024
-struct cdrom_write_settings {
- unsigned char fpacket; /* fixed/variable packets */
- unsigned long packet_size; /* write out this number of packets */
- unsigned long nwa; /* next writeable address */
- unsigned char writeable; /* cdrom is writeable */
+/* 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;
};
+#ifdef __KERNEL__
+#include <linux/devfs_fs_kernel.h>
+
/* Uniform cdrom data structures for cdrom.c */
struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */
@@ -744,7 +773,6 @@ struct cdrom_device_info {
/* per-device flags */
__u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
__u8 reserved : 6; /* not used yet */
- struct cdrom_write_settings write;
};
struct cdrom_device_ops {
@@ -1053,6 +1081,17 @@ typedef struct {
__u8 reserved3;
} rpc_state_t;
-#endif /* End of kernel only stuff */
+struct feature_header {
+ __u32 data_len;
+ __u8 reserved1;
+ __u8 reserved2;
+ __u16 curr_profile;
+};
+
+extern int cdrom_get_disc_info(kdev_t dev, disc_information *di);
+extern int cdrom_get_track_info(kdev_t dev, __u16 track, __u8 type,
+ track_information *ti);
+extern int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write);
+#endif /* __KERNEL__ */
#endif /* _LINUX_CDROM_H */
diff -Nurp linux-2.4.27-pre3/drivers/ide/ide-cd.h linux-2.4.27-pre3-pel/drivers/ide/ide-cd.h
--- linux-2.4.27-pre3/drivers/ide/ide-cd.h 2003-06-13 08:51:33.000000000 -0600
+++ linux-2.4.27-pre3-pel/drivers/ide/ide-cd.h 2004-05-20 15:39:26.589521920 -0600
@@ -2,7 +2,8 @@
* linux/drivers/ide/ide_cd.h
*
* Copyright (C) 1996-98 Erik Andersen
- * Copyright (C) 1998-2000 Jens Axboe
+ * Copyright (C) 1998-2004 Jens Axboe
+ * Copyright (C) 2004 Iomega Corp
*/
#ifndef _IDE_CD_H
#define _IDE_CD_H
@@ -75,6 +76,7 @@ struct ide_cd_config_flags {
__u8 dvd : 1; /* Drive is a DVD-ROM */
__u8 dvd_r : 1; /* Drive can write DVD-R */
__u8 dvd_ram : 1; /* Drive can write DVD-RAM */
+ __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */
__u8 test_write : 1; /* Drive can fake writes */
__u8 supp_disc_present : 1; /* Changer can report exact contents
of slots. */
diff -Nurp linux-2.4.27-pre3/drivers/ide/ide-cd.c linux-2.4.27-pre3-pel/drivers/ide/ide-cd.c
--- linux-2.4.27-pre3/drivers/ide/ide-cd.c 2003-11-28 11:26:20.000000000 -0700
+++ linux-2.4.27-pre3-pel/drivers/ide/ide-cd.c 2004-05-20 15:39:26.614518120 -0600
@@ -3,7 +3,8 @@
*
* Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov>
* Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
- * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 1998-2004 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 2004 Iomega Corp
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
@@ -2683,7 +2684,7 @@ static struct cdrom_device_ops ide_cdrom
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_GENERIC_PACKET | CDC_RAM,
generic_packet: ide_cdrom_packet,
};
@@ -2718,6 +2719,8 @@ static int ide_cdrom_register (ide_drive
devinfo->mask |= CDC_PLAY_AUDIO;
if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
devinfo->mask |= CDC_CLOSE_TRAY;
+ if (!CDROM_CONFIG_FLAGS(drive)->ram)
+ devinfo->mask |= CDC_RAM;
devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
@@ -2766,7 +2769,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 (CDROM_CONFIG_FLAGS(drive)->nec260) {
CDROM_CONFIG_FLAGS(drive)->no_eject = 0;
@@ -2776,7 +2779,9 @@ int ide_cdrom_probe_capabilities (ide_dr
if (ide_cdrom_get_capabilities(drive, &cap))
return 0;
-
+ 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)
@@ -2789,8 +2794,10 @@ int ide_cdrom_probe_capabilities (ide_dr
CDROM_CONFIG_FLAGS(drive)->test_write = 1;
if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
CDROM_CONFIG_FLAGS(drive)->dvd = 1;
- if (cap.dvd_ram_write)
+ if (cap.dvd_ram_write) {
CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1;
+ CDROM_CONFIG_FLAGS(drive)->ram = 1;
+ }
if (cap.dvd_r_write)
CDROM_CONFIG_FLAGS(drive)->dvd_r = 1;
if (cap.audio_play)
@@ -3000,7 +3007,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
nslots = ide_cdrom_probe_capabilities (drive);
- if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
+ if ((CDROM_CONFIG_FLAGS(drive)->dvd_ram) ||
+ (CDROM_CONFIG_FLAGS(drive)->ram))
set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
#if 0
diff -Nurp linux-2.4.27-pre3/drivers/scsi/sr.c linux-2.4.27-pre3-pel/drivers/scsi/sr.c
--- linux-2.4.27-pre3/drivers/scsi/sr.c 2003-06-13 08:51:36.000000000 -0600
+++ linux-2.4.27-pre3-pel/drivers/scsi/sr.c 2004-05-20 15:39:26.615517968 -0600
@@ -1,6 +1,7 @@
/*
* sr.c Copyright (C) 1992 David Giller
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
+ * Copyright (C) 2004 Iomega Corp
*
* adapted from:
* sd.c Copyright (C) 1992 Drew Eckhardt
@@ -128,7 +129,7 @@ static struct cdrom_device_ops sr_dops =
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_DVD_RAM | CDC_GENERIC_PACKET | CDC_RAM,
generic_packet: sr_packet,
};
@@ -693,7 +694,7 @@ void get_capabilities(int i)
{
unsigned char cmd[6];
unsigned char *buffer;
- int rc, n;
+ int rc, n, ram_write=0;
static char *loadmech[] =
{
@@ -731,6 +732,11 @@ void get_capabilities(int i)
printk("sr%i: scsi-1 drive\n", i);
return;
}
+ if (cdrom_is_random_writable(&scsi_CDs[i].cdi, &ram_write))
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+ if (!ram_write)
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+
n = buffer[3] + 4;
scsi_CDs[i].cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
scsi_CDs[i].readcd_known = 1;
@@ -754,8 +760,6 @@ void get_capabilities(int i)
if ((buffer[n + 3] & 0x20) == 0) {
/* can't write DVD-RAM media */
scsi_CDs[i].cdi.mask |= CDC_DVD_RAM;
- } else {
- scsi_CDs[i].device->writeable = 1;
}
if ((buffer[n + 3] & 0x10) == 0)
/* can't write DVD-R media */
@@ -780,6 +784,13 @@ void get_capabilities(int i)
/*else I don't think it can close its tray
scsi_CDs[i].cdi.mask |= CDC_CLOSE_TRAY; */
+ /*
+ * if DVD-RAM of MRW-W, we are randomly writeable
+ */
+ if ((scsi_CDs[i].cdi.mask & (CDC_DVD_RAM | CDC_RAM)) !=
+ (CDC_DVD_RAM | CDC_RAM))
+ scsi_CDs[i].device->writeable = 1;
+
scsi_free(buffer, 512);
}
diff -Nurp linux-2.4.27-pre3/drivers/cdrom/cdrom.c linux-2.4.27-pre3-pel/drivers/cdrom/cdrom.c
--- linux-2.4.27-pre3/drivers/cdrom/cdrom.c 2003-11-28 11:26:20.000000000 -0700
+++ linux-2.4.27-pre3-pel/drivers/cdrom/cdrom.c 2004-05-20 15:39:26.632515384 -0600
@@ -1,7 +1,8 @@
/* linux/drivers/cdrom/cdrom.c.
Copyright (c) 1996, 1997 David A. van Leeuwen.
Copyright (c) 1997, 1998 Erik Andersen <andersee@debian.org>
- Copyright (c) 1998, 1999 Jens Axboe <axboe@image.dk>
+ Copyright (c) 1998-2004 Jens Axboe <axboe@image.dk>
+ Copyright (c) 2004, Iomega Corp.
May be copied or modified under the terms of the GNU General Public
License. See linux/COPYING for more information.
@@ -447,6 +448,112 @@ struct cdrom_device_info *cdrom_find_dev
return cdi;
}
+int cdrom_get_random_writable(struct cdrom_device_info *cdi,
+ struct rwrt_feature_desc *rfd)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[24];
+ struct feature_header *fh;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_RWRT; /* often 0x0020 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x18 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+
+ sizeof(struct rwrt_feature_desc)))
+ memcpy(rfd, &buffer[sizeof(struct feature_header)],
+ sizeof (*rfd));
+ else
+ memset(rfd, 0, sizeof(*rfd));
+
+ return 0;
+}
+
+int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[16];
+ struct feature_header *fh;
+ __u16 *feature_code;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_HWDM; /* often 0x0024 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x10 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ ret = 1;
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+8)) {
+ feature_code = (__u16 *)&buffer[sizeof(struct feature_header)];
+ if (CDF_HWDM == be16_to_cpu(*feature_code))
+ ret = 0;
+ }
+ return ret;
+}
+
+
+int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ *write = 0;
+
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+
+ if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ *write = 1;
+
+ return 0;
+}
+
+static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ if ((ret = cdrom_has_defect_mgt(cdi)))
+ return ret;
+ else
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+ else if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ ret = !rfd.curr;
+
+ cdinfo(CD_OPEN, "can open for random write\n");
+ return ret;
+}
+
+/*
+ * returns 0 for ok to open write, non-0 to disallow
+ */
+static int cdrom_open_write(struct cdrom_device_info *cdi)
+{
+ int ret;
+ if (CDROM_CAN(CDC_RAM) &&
+ !CDROM_CAN(CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R))
+ ret = cdrom_ram_open_write(cdi);
+ else
+ ret = 1;
+
+ return ret;
+}
+
/* We use the open-option O_NONBLOCK to indicate that the
* purpose of opening is only for subsequent ioctl() calls; no device
* integrity checks are performed.
@@ -465,8 +572,15 @@ int cdrom_open(struct inode *ip, struct
if ((cdi = cdrom_find_device(dev)) == NULL)
return -ENODEV;
- if ((fp->f_mode & FMODE_WRITE) && !CDROM_CAN(CDC_DVD_RAM))
- return -EROFS;
+ cdi->use_count++;
+ ret = -EROFS;
+ if (fp->f_mode & FMODE_WRITE) {
+ /* printk("cdrom: %s opening for WRITE\n", current->comm); */
+ if (!CDROM_CAN(CDC_RAM))
+ goto out;
+ if (cdrom_open_write(cdi))
+ goto out;
+ }
/* if this was a O_NONBLOCK open and we should honor the flags,
* do a quick open without drive/disc integrity checks. */
@@ -475,12 +589,13 @@ int cdrom_open(struct inode *ip, struct
else
ret = open_for_data(cdi);
- if (!ret) cdi->use_count++;
-
cdinfo(CD_OPEN, "Use count for \"/dev/%s\" now %d\n", cdi->name, cdi->use_count);
/* Do this on open. Don't wait for mount, because they might
not be mounting, but opening with O_NONBLOCK */
check_disk_change(dev);
+out:
+ if (ret)
+ cdi->use_count--;
return ret;
}
@@ -657,15 +772,14 @@ int cdrom_release(struct inode *ip, stru
cdinfo(CD_CLOSE, "entering cdrom_release\n");
- if (cdi->use_count > 0)
- cdi->use_count--;
- if (cdi->use_count == 0)
+ if (!--cdi->use_count) {
cdinfo(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n", cdi->name);
- if (cdi->use_count == 0 &&
- cdo->capability & CDC_LOCK && !keeplocked) {
- cdinfo(CD_CLOSE, "Unlocking door!\n");
- cdo->lock_door(cdi, 0);
+ if ((cdo->capability & CDC_LOCK) && !keeplocked) {
+ cdinfo(CD_CLOSE, "Unlocking door!\n");
+ cdo->lock_door(cdi, 0);
+ }
}
+
opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
!(fp && fp->f_flags & O_NONBLOCK);
cdo->release(cdi);
@@ -1909,10 +2023,24 @@ static int cdrom_do_cmd(struct cdrom_dev
}
}
+ /*
+ * queue command and wait for it to complete
+ */
ret = cdi->ops->generic_packet(cdi, cgc);
- __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * always copy back sense, command need not have failed for it to
+ * contain useful info
+ */
+ if (usense)
+ __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * this really needs to be modified to copy back good bytes
+ */
if (!ret && cgc->data_direction == CGC_DATA_READ)
__copy_to_user(ubuf, cgc->buffer, cgc->buflen);
+
if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
kfree(cgc->buffer);
@@ -2392,6 +2520,7 @@ EXPORT_SYMBOL(cdrom_mode_select);
EXPORT_SYMBOL(cdrom_mode_sense);
EXPORT_SYMBOL(init_cdrom_command);
EXPORT_SYMBOL(cdrom_find_device);
+EXPORT_SYMBOL(cdrom_is_random_writable);
#ifdef CONFIG_SYSCTL
@@ -2488,6 +2617,10 @@ int cdrom_sysctl_info(ctl_table *ctl, in
for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_DVD_RAM) != 0);
+ pos += sprintf(info+pos, "\nCan write RAM:\t");
+ for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
+ pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_RAM) != 0);
+
strcpy(info+pos,"\n\n");
return proc_dostring(ctl, write, filp, buffer, lenp);
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-20 22:01 ` Pat LaVarre
@ 2004-05-20 23:51 ` Pat LaVarre
2004-05-21 6:53 ` Jens Axboe
1 sibling, 0 replies; 20+ messages in thread
From: Pat LaVarre @ 2004-05-20 23:51 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
> ... inline below for your convenience.
>
> Also I will install & reboot & look for trouble.
No trouble found, in the search quoted below.
Pat LaVarre
$ uname -r
2.4.27-pre3
$
$ sudo mkudffs /dev/hdc
...
$ sudo mkudffs /dev/scd0
...
$
$ sudo mount /dev/hdc /mnt/hdc
$ sudo mount /dev/scd0 /mnt/scd0
$ mount | grep mnt
/dev/hdc on /mnt/hdc type udf (rw)
/dev/scd0 on /mnt/scd0 type udf (rw)
$
$ sudo umount /dev/hdc /dev/scd0
$
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-20 22:01 ` Pat LaVarre
2004-05-20 23:51 ` Pat LaVarre
@ 2004-05-21 6:53 ` Jens Axboe
2004-05-21 15:28 ` Pat LaVarre
1 sibling, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-05-21 6:53 UTC (permalink / raw)
To: Pat LaVarre; +Cc: linux-scsi, John McKell
On Thu, May 20 2004, Pat LaVarre wrote:
> diff confirms for me the patch inline of this post matches what John
> McKell posted, except for the trivial difference of folder names & dates
> and the substantive difference that I did comment out the per-open
> printk:
>
> - + printk("cdrom: %s opening for WRITE\n", current->comm);
> + + /* printk("cdrom: %s opening for WRITE\n", current->comm); */
That's fine, I killed that in 2.6 as well.
> > > I believe 2.4.18 patch actually makes `mount -w` work there by way of
> > > "see all DVD/CD drives as DVD-RAM/ DVD-ROM compatible".
> >
> > But that's not what the patch does at all. The patch simply says "If we
> > succeeded in retriving the mode capability page, ignore what it says and
> > flag the drive as dvd-rom/ram capable" which is clearly bogus.
>
> To newbie me, this is not clearly bogus, sorry.
>
> 1)
>
> I see my 2.4.18 patch makes `mount -w` work, by way of breaking `cat
> /proc/sys/dev/cdrom/info`.
>
> mount matters more to me than proc.
>
> Besides, the breakage is small. I'm not falsely claiming that a DVD-RAM
> disc is present. I'm only falsely claiming that a DVD-RAM disc could be
> present. Software that branches visibly on which kind of disc might
> someday be present looks very nearly bogus to me.
Sorry, I still think this is completely bogus. No point in debating it,
there's no way that hack will go into the 2.4 kernels.
> 2)
>
> I see my 2.4.18 patch is extremely short and simple.
>
> Simplicity in the patch matters more to me the further I step back from
> the latest available at kernel.org.
Your 2.4.18 patch is a hack.
> diff -Nurp linux-2.4.27-pre3/include/linux/cdrom.h linux-2.4.27-pre3-pel/include/linux/cdrom.h
[snip]
Patch looks fine to me, I'll send it to Marcelo for inclusion. Thanks!
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-21 6:53 ` Jens Axboe
@ 2004-05-21 15:28 ` Pat LaVarre
2004-06-03 18:30 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-05-21 15:28 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
> > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
>
> [snip]
>
> Patch looks fine to me,
> I'll send it to Marcelo for inclusion. Thanks!
Wonderful news, thank you both, consequently now with more hope I look
forward to writing kernel patches exclusively for 2.6.
> Your 2.4.18 patch is a hack.
Yes.
> No point in debating ...
I agree I will not now confirm my new understanding of what the word
"bogus" means to you.
Pat LaVarre
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-05-21 15:28 ` Pat LaVarre
@ 2004-06-03 18:30 ` Pat LaVarre
2004-06-03 18:32 ` Jens Axboe
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-06-03 18:30 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-scsi, John McKell
Jens A:
> > http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562
> > > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
> >
> > [snip]
> >
> > Patch looks fine to me,
> > I'll send it to Marcelo for inclusion. Thanks!
>
> Wonderful news, thank you both, consequently now with more hope I look
> forward to writing kernel patches exclusively for 2.6.
Today 2004-6-3 I see no mention of the 5-21 CDC_RAM for lk 2.4 patch
near such strings as "Marcelo" and "Axboe" in:
http://www.kernel.org/pub/linux/kernel/v2.4/testing/patch-2.4.27.log
I will think go on naively believing that is the right place to poll
until someone tells me different (or we all start working 2.4.28).
Pat LaVarre
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-03 18:30 ` Pat LaVarre
@ 2004-06-03 18:32 ` Jens Axboe
2004-06-04 14:53 ` Marcelo Tosatti
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-06-03 18:32 UTC (permalink / raw)
To: Pat LaVarre; +Cc: linux-scsi, John McKell, Marcelo
On Thu, Jun 03 2004, Pat LaVarre wrote:
> Jens A:
>
> > > http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562
> > > > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
> > >
> > > [snip]
> > >
> > > Patch looks fine to me,
> > > I'll send it to Marcelo for inclusion. Thanks!
> >
> > Wonderful news, thank you both, consequently now with more hope I look
> > forward to writing kernel patches exclusively for 2.6.
>
> Today 2004-6-3 I see no mention of the 5-21 CDC_RAM for lk 2.4 patch
> near such strings as "Marcelo" and "Axboe" in:
>
> http://www.kernel.org/pub/linux/kernel/v2.4/testing/patch-2.4.27.log
>
> I will think go on naively believing that is the right place to poll
> until someone tells me different (or we all start working 2.4.28).
It was sent to Marcelo, and he even asked for a resend since he lost it.
Marcelo, do you still have it or should I send it again?
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-03 18:32 ` Jens Axboe
@ 2004-06-04 14:53 ` Marcelo Tosatti
2004-06-04 15:18 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Marcelo Tosatti @ 2004-06-04 14:53 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pat LaVarre, linux-scsi, John McKell
On Thu, Jun 03, 2004 at 08:32:17PM +0200, Jens Axboe wrote:
> On Thu, Jun 03 2004, Pat LaVarre wrote:
> > Jens A:
> >
> > > > http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562
> > > > > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
> > > >
> > > > [snip]
> > > >
> > > > Patch looks fine to me,
> > > > I'll send it to Marcelo for inclusion. Thanks!
> > >
> > > Wonderful news, thank you both, consequently now with more hope I look
> > > forward to writing kernel patches exclusively for 2.6.
> >
> > Today 2004-6-3 I see no mention of the 5-21 CDC_RAM for lk 2.4 patch
> > near such strings as "Marcelo" and "Axboe" in:
> >
> > http://www.kernel.org/pub/linux/kernel/v2.4/testing/patch-2.4.27.log
> >
> > I will think go on naively believing that is the right place to poll
> > until someone tells me different (or we all start working 2.4.28).
>
> It was sent to Marcelo, and he even asked for a resend since he lost it.
> Marcelo, do you still have it or should I send it again?
Terribly sorry for losing this contribution, yet another time.
Please resend me.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-04 14:53 ` Marcelo Tosatti
@ 2004-06-04 15:18 ` Pat LaVarre
2004-06-04 15:24 ` Jens Axboe
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-06-04 15:18 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: linux-scsi, Jens Axboe, John McKell
Marcelo T:
> > > > > http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562
> > > > > > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
> > > > >
> > > > > [snip]
> > > > >
> > > > > Patch looks fine to me,
> > > > > I'll send it to Marcelo for inclusion. Thanks!
> ...
> Please resend me.
Thank you for helping.
Inline below is a copy of the Axboe-approved version, taken from:
http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562&q=raw
Be aware, meanwhile, offline an issue has arisen in 2.6 whose fix is
also now being backported to 2.4. I don't myself yet fully understand
that discussion, but I will try to post a 2.4 fix today here (UTC-7+1).
Please tell me if you want one combined substitute patch, or an
incremental like 2.6 gets.
Pat LaVarre
diff -Nurp linux-2.4.27-pre3/include/linux/cdrom.h linux-2.4.27-pre3-pel/include/linux/cdrom.h
--- linux-2.4.27-pre3/include/linux/cdrom.h 2001-11-22 12:47:04.000000000 -0700
+++ linux-2.4.27-pre3-pel/include/linux/cdrom.h 2004-05-20 15:39:26.573524352 -0600
@@ -5,7 +5,8 @@
* 1994, 1995 Eberhard Moenkeberg, emoenke@gwdg.de
* 1996 David van Leeuwen, david@tm.tno.nl
* 1997, 1998 Erik Andersen, andersee@debian.org
- * 1998-2000 Jens Axboe, axboe@suse.de
+ * 1998-2004 Jens Axboe, axboe@suse.de
+ * 2004 Iomega Corp
*/
#ifndef _LINUX_CDROM_H
@@ -387,6 +388,7 @@ struct cdrom_generic_command
#define CDC_DVD 0x8000 /* drive is a DVD */
#define CDC_DVD_R 0x10000 /* drive can write DVD-R */
#define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
+#define CDC_RAM 0x100000 /* ok to open WRITE */
/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
#define CDS_NO_INFO 0 /* if not implemented */
@@ -714,16 +716,43 @@ struct request_sense {
__u8 asb[46];
};
-#ifdef __KERNEL__
-#include <linux/devfs_fs_kernel.h>
+/*
+ * feature profile
+ */
+#define CDF_RWRT 0x0020
+#define CDF_HWDM 0x0024
-struct cdrom_write_settings {
- unsigned char fpacket; /* fixed/variable packets */
- unsigned long packet_size; /* write out this number of packets */
- unsigned long nwa; /* next writeable address */
- unsigned char writeable; /* cdrom is writeable */
+/* 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;
};
+#ifdef __KERNEL__
+#include <linux/devfs_fs_kernel.h>
+
/* Uniform cdrom data structures for cdrom.c */
struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */
@@ -744,7 +773,6 @@ struct cdrom_device_info {
/* per-device flags */
__u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
__u8 reserved : 6; /* not used yet */
- struct cdrom_write_settings write;
};
struct cdrom_device_ops {
@@ -1053,6 +1081,17 @@ typedef struct {
__u8 reserved3;
} rpc_state_t;
-#endif /* End of kernel only stuff */
+struct feature_header {
+ __u32 data_len;
+ __u8 reserved1;
+ __u8 reserved2;
+ __u16 curr_profile;
+};
+
+extern int cdrom_get_disc_info(kdev_t dev, disc_information *di);
+extern int cdrom_get_track_info(kdev_t dev, __u16 track, __u8 type,
+ track_information *ti);
+extern int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write);
+#endif /* __KERNEL__ */
#endif /* _LINUX_CDROM_H */
diff -Nurp linux-2.4.27-pre3/drivers/ide/ide-cd.h linux-2.4.27-pre3-pel/drivers/ide/ide-cd.h
--- linux-2.4.27-pre3/drivers/ide/ide-cd.h 2003-06-13 08:51:33.000000000 -0600
+++ linux-2.4.27-pre3-pel/drivers/ide/ide-cd.h 2004-05-20 15:39:26.589521920 -0600
@@ -2,7 +2,8 @@
* linux/drivers/ide/ide_cd.h
*
* Copyright (C) 1996-98 Erik Andersen
- * Copyright (C) 1998-2000 Jens Axboe
+ * Copyright (C) 1998-2004 Jens Axboe
+ * Copyright (C) 2004 Iomega Corp
*/
#ifndef _IDE_CD_H
#define _IDE_CD_H
@@ -75,6 +76,7 @@ struct ide_cd_config_flags {
__u8 dvd : 1; /* Drive is a DVD-ROM */
__u8 dvd_r : 1; /* Drive can write DVD-R */
__u8 dvd_ram : 1; /* Drive can write DVD-RAM */
+ __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */
__u8 test_write : 1; /* Drive can fake writes */
__u8 supp_disc_present : 1; /* Changer can report exact contents
of slots. */
diff -Nurp linux-2.4.27-pre3/drivers/ide/ide-cd.c linux-2.4.27-pre3-pel/drivers/ide/ide-cd.c
--- linux-2.4.27-pre3/drivers/ide/ide-cd.c 2003-11-28 11:26:20.000000000 -0700
+++ linux-2.4.27-pre3-pel/drivers/ide/ide-cd.c 2004-05-20 15:39:26.614518120 -0600
@@ -3,7 +3,8 @@
*
* Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov>
* Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
- * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 1998-2004 Jens Axboe <axboe@suse.de>
+ * Copyright (C) 2004 Iomega Corp
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
@@ -2683,7 +2684,7 @@ static struct cdrom_device_ops ide_cdrom
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_GENERIC_PACKET | CDC_RAM,
generic_packet: ide_cdrom_packet,
};
@@ -2718,6 +2719,8 @@ static int ide_cdrom_register (ide_drive
devinfo->mask |= CDC_PLAY_AUDIO;
if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
devinfo->mask |= CDC_CLOSE_TRAY;
+ if (!CDROM_CONFIG_FLAGS(drive)->ram)
+ devinfo->mask |= CDC_RAM;
devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
@@ -2766,7 +2769,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 (CDROM_CONFIG_FLAGS(drive)->nec260) {
CDROM_CONFIG_FLAGS(drive)->no_eject = 0;
@@ -2776,7 +2779,9 @@ int ide_cdrom_probe_capabilities (ide_dr
if (ide_cdrom_get_capabilities(drive, &cap))
return 0;
-
+ 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)
@@ -2789,8 +2794,10 @@ int ide_cdrom_probe_capabilities (ide_dr
CDROM_CONFIG_FLAGS(drive)->test_write = 1;
if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
CDROM_CONFIG_FLAGS(drive)->dvd = 1;
- if (cap.dvd_ram_write)
+ if (cap.dvd_ram_write) {
CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1;
+ CDROM_CONFIG_FLAGS(drive)->ram = 1;
+ }
if (cap.dvd_r_write)
CDROM_CONFIG_FLAGS(drive)->dvd_r = 1;
if (cap.audio_play)
@@ -3000,7 +3007,8 @@ int ide_cdrom_setup (ide_drive_t *drive)
nslots = ide_cdrom_probe_capabilities (drive);
- if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
+ if ((CDROM_CONFIG_FLAGS(drive)->dvd_ram) ||
+ (CDROM_CONFIG_FLAGS(drive)->ram))
set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
#if 0
diff -Nurp linux-2.4.27-pre3/drivers/scsi/sr.c linux-2.4.27-pre3-pel/drivers/scsi/sr.c
--- linux-2.4.27-pre3/drivers/scsi/sr.c 2003-06-13 08:51:36.000000000 -0600
+++ linux-2.4.27-pre3-pel/drivers/scsi/sr.c 2004-05-20 15:39:26.615517968 -0600
@@ -1,6 +1,7 @@
/*
* sr.c Copyright (C) 1992 David Giller
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
+ * Copyright (C) 2004 Iomega Corp
*
* adapted from:
* sd.c Copyright (C) 1992 Drew Eckhardt
@@ -128,7 +129,7 @@ static struct cdrom_device_ops sr_dops =
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_DVD_RAM | CDC_GENERIC_PACKET | CDC_RAM,
generic_packet: sr_packet,
};
@@ -693,7 +694,7 @@ void get_capabilities(int i)
{
unsigned char cmd[6];
unsigned char *buffer;
- int rc, n;
+ int rc, n, ram_write=0;
static char *loadmech[] =
{
@@ -731,6 +732,11 @@ void get_capabilities(int i)
printk("sr%i: scsi-1 drive\n", i);
return;
}
+ if (cdrom_is_random_writable(&scsi_CDs[i].cdi, &ram_write))
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+ if (!ram_write)
+ scsi_CDs[i].cdi.mask |= CDC_RAM;
+
n = buffer[3] + 4;
scsi_CDs[i].cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
scsi_CDs[i].readcd_known = 1;
@@ -754,8 +760,6 @@ void get_capabilities(int i)
if ((buffer[n + 3] & 0x20) == 0) {
/* can't write DVD-RAM media */
scsi_CDs[i].cdi.mask |= CDC_DVD_RAM;
- } else {
- scsi_CDs[i].device->writeable = 1;
}
if ((buffer[n + 3] & 0x10) == 0)
/* can't write DVD-R media */
@@ -780,6 +784,13 @@ void get_capabilities(int i)
/*else I don't think it can close its tray
scsi_CDs[i].cdi.mask |= CDC_CLOSE_TRAY; */
+ /*
+ * if DVD-RAM of MRW-W, we are randomly writeable
+ */
+ if ((scsi_CDs[i].cdi.mask & (CDC_DVD_RAM | CDC_RAM)) !=
+ (CDC_DVD_RAM | CDC_RAM))
+ scsi_CDs[i].device->writeable = 1;
+
scsi_free(buffer, 512);
}
diff -Nurp linux-2.4.27-pre3/drivers/cdrom/cdrom.c linux-2.4.27-pre3-pel/drivers/cdrom/cdrom.c
--- linux-2.4.27-pre3/drivers/cdrom/cdrom.c 2003-11-28 11:26:20.000000000 -0700
+++ linux-2.4.27-pre3-pel/drivers/cdrom/cdrom.c 2004-05-20 15:39:26.632515384 -0600
@@ -1,7 +1,8 @@
/* linux/drivers/cdrom/cdrom.c.
Copyright (c) 1996, 1997 David A. van Leeuwen.
Copyright (c) 1997, 1998 Erik Andersen <andersee@debian.org>
- Copyright (c) 1998, 1999 Jens Axboe <axboe@image.dk>
+ Copyright (c) 1998-2004 Jens Axboe <axboe@image.dk>
+ Copyright (c) 2004, Iomega Corp.
May be copied or modified under the terms of the GNU General Public
License. See linux/COPYING for more information.
@@ -447,6 +448,112 @@ struct cdrom_device_info *cdrom_find_dev
return cdi;
}
+int cdrom_get_random_writable(struct cdrom_device_info *cdi,
+ struct rwrt_feature_desc *rfd)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[24];
+ struct feature_header *fh;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_RWRT; /* often 0x0020 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x18 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+
+ sizeof(struct rwrt_feature_desc)))
+ memcpy(rfd, &buffer[sizeof(struct feature_header)],
+ sizeof (*rfd));
+ else
+ memset(rfd, 0, sizeof(*rfd));
+
+ return 0;
+}
+
+int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[16];
+ struct feature_header *fh;
+ __u16 *feature_code;
+ int ret;
+
+ init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
+
+ cgc.cmd[0] = GPCMD_GET_CONFIGURATION; /* often 0x46 */
+ cgc.cmd[3] = CDF_HWDM; /* often 0x0024 */
+ cgc.cmd[8] = sizeof(buffer); /* often 0x10 */
+ cgc.quiet = 1;
+
+ if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
+ return ret;
+
+ fh = (struct feature_header *)&buffer[0];
+ ret = 1;
+ if (be32_to_cpu(fh->data_len) >= (sizeof(struct feature_header)+8)) {
+ feature_code = (__u16 *)&buffer[sizeof(struct feature_header)];
+ if (CDF_HWDM == be16_to_cpu(*feature_code))
+ ret = 0;
+ }
+ return ret;
+}
+
+
+int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ *write = 0;
+
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+
+ if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ *write = 1;
+
+ return 0;
+}
+
+static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
+{
+ struct rwrt_feature_desc rfd;
+ int ret;
+
+ if ((ret = cdrom_has_defect_mgt(cdi)))
+ return ret;
+ else
+ if ((ret = cdrom_get_random_writable(cdi, &rfd)))
+ return ret;
+ else if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
+ ret = !rfd.curr;
+
+ cdinfo(CD_OPEN, "can open for random write\n");
+ return ret;
+}
+
+/*
+ * returns 0 for ok to open write, non-0 to disallow
+ */
+static int cdrom_open_write(struct cdrom_device_info *cdi)
+{
+ int ret;
+ if (CDROM_CAN(CDC_RAM) &&
+ !CDROM_CAN(CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R))
+ ret = cdrom_ram_open_write(cdi);
+ else
+ ret = 1;
+
+ return ret;
+}
+
/* We use the open-option O_NONBLOCK to indicate that the
* purpose of opening is only for subsequent ioctl() calls; no device
* integrity checks are performed.
@@ -465,8 +572,15 @@ int cdrom_open(struct inode *ip, struct
if ((cdi = cdrom_find_device(dev)) == NULL)
return -ENODEV;
- if ((fp->f_mode & FMODE_WRITE) && !CDROM_CAN(CDC_DVD_RAM))
- return -EROFS;
+ cdi->use_count++;
+ ret = -EROFS;
+ if (fp->f_mode & FMODE_WRITE) {
+ /* printk("cdrom: %s opening for WRITE\n", current->comm); */
+ if (!CDROM_CAN(CDC_RAM))
+ goto out;
+ if (cdrom_open_write(cdi))
+ goto out;
+ }
/* if this was a O_NONBLOCK open and we should honor the flags,
* do a quick open without drive/disc integrity checks. */
@@ -475,12 +589,13 @@ int cdrom_open(struct inode *ip, struct
else
ret = open_for_data(cdi);
- if (!ret) cdi->use_count++;
-
cdinfo(CD_OPEN, "Use count for \"/dev/%s\" now %d\n", cdi->name, cdi->use_count);
/* Do this on open. Don't wait for mount, because they might
not be mounting, but opening with O_NONBLOCK */
check_disk_change(dev);
+out:
+ if (ret)
+ cdi->use_count--;
return ret;
}
@@ -657,15 +772,14 @@ int cdrom_release(struct inode *ip, stru
cdinfo(CD_CLOSE, "entering cdrom_release\n");
- if (cdi->use_count > 0)
- cdi->use_count--;
- if (cdi->use_count == 0)
+ if (!--cdi->use_count) {
cdinfo(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n", cdi->name);
- if (cdi->use_count == 0 &&
- cdo->capability & CDC_LOCK && !keeplocked) {
- cdinfo(CD_CLOSE, "Unlocking door!\n");
- cdo->lock_door(cdi, 0);
+ if ((cdo->capability & CDC_LOCK) && !keeplocked) {
+ cdinfo(CD_CLOSE, "Unlocking door!\n");
+ cdo->lock_door(cdi, 0);
+ }
}
+
opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
!(fp && fp->f_flags & O_NONBLOCK);
cdo->release(cdi);
@@ -1909,10 +2023,24 @@ static int cdrom_do_cmd(struct cdrom_dev
}
}
+ /*
+ * queue command and wait for it to complete
+ */
ret = cdi->ops->generic_packet(cdi, cgc);
- __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * always copy back sense, command need not have failed for it to
+ * contain useful info
+ */
+ if (usense)
+ __copy_to_user(usense, cgc->sense, sizeof(*usense));
+
+ /*
+ * this really needs to be modified to copy back good bytes
+ */
if (!ret && cgc->data_direction == CGC_DATA_READ)
__copy_to_user(ubuf, cgc->buffer, cgc->buflen);
+
if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
kfree(cgc->buffer);
@@ -2392,6 +2520,7 @@ EXPORT_SYMBOL(cdrom_mode_select);
EXPORT_SYMBOL(cdrom_mode_sense);
EXPORT_SYMBOL(init_cdrom_command);
EXPORT_SYMBOL(cdrom_find_device);
+EXPORT_SYMBOL(cdrom_is_random_writable);
#ifdef CONFIG_SYSCTL
@@ -2488,6 +2617,10 @@ int cdrom_sysctl_info(ctl_table *ctl, in
for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_DVD_RAM) != 0);
+ pos += sprintf(info+pos, "\nCan write RAM:\t");
+ for (cdi=topCdromPtr;cdi!=NULL;cdi=cdi->next)
+ pos += sprintf(info+pos, "\t%d", CDROM_CAN(CDC_RAM) != 0);
+
strcpy(info+pos,"\n\n");
return proc_dostring(ctl, write, filp, buffer, lenp);
-
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-04 15:18 ` Pat LaVarre
@ 2004-06-04 15:24 ` Jens Axboe
2004-06-04 15:27 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-06-04 15:24 UTC (permalink / raw)
To: Pat LaVarre; +Cc: Marcelo Tosatti, linux-scsi, John McKell
On Fri, Jun 04 2004, Pat LaVarre wrote:
> Marcelo T:
>
> > > > > > http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562
> > > > > > > diff -Nurp linux-2.4.27-pre3/... linux-2.4.27-pre3-pel/...
> > > > > >
> > > > > > [snip]
> > > > > >
> > > > > > Patch looks fine to me,
> > > > > > I'll send it to Marcelo for inclusion. Thanks!
> > ...
> > Please resend me.
>
> Thank you for helping.
>
> Inline below is a copy of the Axboe-approved version, taken from:
>
> http://marc.theaimsgroup.com/?l=linux-scsi&m=108509426227562&q=raw
>
> Be aware, meanwhile, offline an issue has arisen in 2.6 whose fix is
> also now being backported to 2.4. I don't myself yet fully understand
> that discussion, but I will try to post a 2.4 fix today here (UTC-7+1).
>
> Please tell me if you want one combined substitute patch, or an
> incremental like 2.6 gets.
I already sent an updated to Marcelo 5 minutes ago which has that fixed
incorporated. JFYI Marcelo, apply that version and the above is void.
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-04 15:24 ` Jens Axboe
@ 2004-06-04 15:27 ` Pat LaVarre
2004-06-04 15:36 ` Jens Axboe
0 siblings, 1 reply; 20+ messages in thread
From: Pat LaVarre @ 2004-06-04 15:27 UTC (permalink / raw)
To: Jens Axboe; +Cc: Marcelo Tosatti, linux-scsi, John McKell
> I already sent an updated to Marcelo 5 minutes ago which has that fixed
> incorporated. JFYI Marcelo, apply that version and the above is void.
Thank you.
Therefore, absolutely no work remains for me? I cannot help further?
Pat LaVarre
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-04 15:27 ` Pat LaVarre
@ 2004-06-04 15:36 ` Jens Axboe
2004-06-18 21:42 ` Pat LaVarre
0 siblings, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2004-06-04 15:36 UTC (permalink / raw)
To: Pat LaVarre; +Cc: Marcelo Tosatti, linux-scsi, John McKell
On Fri, Jun 04 2004, Pat LaVarre wrote:
> > I already sent an updated to Marcelo 5 minutes ago which has that fixed
> > incorporated. JFYI Marcelo, apply that version and the above is void.
>
> Thank you.
>
> Therefore, absolutely no work remains for me? I cannot help further?
No work remains :)
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: CDC_RAM for lk 2.4, PATCH proposed
2004-06-04 15:36 ` Jens Axboe
@ 2004-06-18 21:42 ` Pat LaVarre
0 siblings, 0 replies; 20+ messages in thread
From: Pat LaVarre @ 2004-06-18 21:42 UTC (permalink / raw)
To: John McKell; +Cc: linux-scsi
Thanks again to everyone.
2.4.27-pre6 here now of rewritable RMB MMC UDF looks better than 2.6.6,
indeed as good as 2.6.7.
Pat LaVarre
-----
http://www.kernel.org/pub/linux/kernel/v2.4/testing/patch-2.4.27.log
Summary of changes ... to v2.4.27-pre6
...
Jens Axboe:
o DVD-RW write support
o cdrom hardware defect mgt header length
...
Summary of changes from v2.4.26 ...
...
-----
$ uname -r
2.4.27-pre6
$
$ sudo mkudffs /dev/scd0
...
$ sudo mount /dev/scd0 /mnt/scd0
$ mount | grep scd0
/dev/scd0 on /mnt/scd0 type udf (rw)
$ sudo umount /dev/scd0
$
$ sudo rrd scan
/dev/scd0 is Iomega RRD 74.B rw
$
$ sudo eject /dev/scd0
$
$ sudo mount -r /dev/scd0 /mnt/scd0
$ ls -l /mnt/scd0
total 20
-rw-rw-rw- 1 4294967295 4294967295 25 Jun 17 14:01 Autorun.inf
-rw-rw-rw- 1 4294967295 4294967295 18902 Feb 5 08:35 REV.ico
$ sudo umount /dev/scd0
$
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2004-06-18 21:43 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-15 16:52 CDC_RAM for lk 2.4, PATCH proposed Pat LaVarre
2004-04-16 12:09 ` Jens Axboe
2004-04-23 22:25 ` John McKell
2004-04-28 1:46 ` Pat LaVarre
2004-04-28 14:48 ` Pat LaVarre
[not found] ` <1084897080.3746.38.camel@patibmrh9>
2004-05-19 8:15 ` Jens Axboe
2004-05-19 15:45 ` Pat LaVarre
2004-05-20 8:06 ` Jens Axboe
2004-05-20 22:01 ` Pat LaVarre
2004-05-20 23:51 ` Pat LaVarre
2004-05-21 6:53 ` Jens Axboe
2004-05-21 15:28 ` Pat LaVarre
2004-06-03 18:30 ` Pat LaVarre
2004-06-03 18:32 ` Jens Axboe
2004-06-04 14:53 ` Marcelo Tosatti
2004-06-04 15:18 ` Pat LaVarre
2004-06-04 15:24 ` Jens Axboe
2004-06-04 15:27 ` Pat LaVarre
2004-06-04 15:36 ` Jens Axboe
2004-06-18 21:42 ` Pat LaVarre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox