* cdrom blocksize reset bug with 2.4.x kernels @ 2003-07-01 22:25 Attila Kinali 2003-07-02 11:18 ` Jens Axboe 0 siblings, 1 reply; 4+ messages in thread From: Attila Kinali @ 2003-07-01 22:25 UTC (permalink / raw) To: axboe; +Cc: linux-kernel [-- Attachment #1: Type: text/plain, Size: 1212 bytes --] Hi, After some discussion on the mplayer-users mailinglist about that for some scsi drives it's impossible to read a data cd after reading a vcd/scvd until the next reboot. (see http://mplayerhq.hu/pipermail/mplayer-users/2002-December/025696.html) I found that there is a reset of the cdrom block size needed for those drives which doesnt restet it themselfs if a new cd is put in (looks like only a few scsi cdroms are affected) Attached is a small patch for drivers/cdrom/cdrom.c that fixes this for the 2.4.20 kernel (and also for 2.4.21 as the code didn't change). It's reseting the blocksize when a cdrom is opened for the first time (meaning that a umount/mount cycle can reset the blocksize). I run this code now for about half a year and didnt have any problems. But, as i didnt get any feadback from other people, i'm not sure if everything is correct. Greetings Attila Kinali -- Emacs ist für mich kein Editor. Für mich ist das genau das gleiche, als wenn ich nach einem Fahrrad (für die Sonntagbrötchen) frage und einen pangalaktischen Raumkreuzer mit 10 km Gesamtlänge bekomme. Ich weiß nicht, was ich damit soll. -- Frank Klemm, de.comp.os.unix.discussion [-- Attachment #2: cdrom-blocksize.patch --] [-- Type: application/octet-stream, Size: 509 bytes --] --- cdrom.c.orig 2003-01-05 15:02:53.000000000 +0100 +++ cdrom.c 2003-01-05 15:05:44.000000000 +0100 @@ -475,7 +475,15 @@ else ret = open_for_data(cdi); - if (!ret) cdi->use_count++; + if (!ret) + { + cdi->use_count++; + if(cdi->use_count == 1) + { + /* reset blocksize in case it's wrong */ + cdrom_switch_blocksize(cdi,CD_FRAMESIZE); + } + } 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cdrom blocksize reset bug with 2.4.x kernels 2003-07-01 22:25 cdrom blocksize reset bug with 2.4.x kernels Attila Kinali @ 2003-07-02 11:18 ` Jens Axboe 2003-11-09 14:56 ` Tobias Diedrich 0 siblings, 1 reply; 4+ messages in thread From: Jens Axboe @ 2003-07-02 11:18 UTC (permalink / raw) To: Attila Kinali; +Cc: linux-kernel On Wed, Jul 02 2003, Attila Kinali wrote: > Hi, > > After some discussion on the mplayer-users mailinglist about > that for some scsi drives it's impossible to read a data cd > after reading a vcd/scvd until the next reboot. > (see http://mplayerhq.hu/pipermail/mplayer-users/2002-December/025696.html) > > I found that there is a reset of the cdrom block size needed > for those drives which doesnt restet it themselfs if a new > cd is put in (looks like only a few scsi cdroms are affected) > > Attached is a small patch for drivers/cdrom/cdrom.c that fixes > this for the 2.4.20 kernel (and also for 2.4.21 as the code didn't > change). It's reseting the blocksize when a cdrom is opened for > the first time (meaning that a umount/mount cycle can reset > the blocksize). > > I run this code now for about half a year and didnt have any problems. > But, as i didnt get any feadback from other people, i'm not sure if > everything is correct. If you clean this up wrt coding style, it can go in. -- Jens Axboe ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cdrom blocksize reset bug with 2.4.x kernels 2003-07-02 11:18 ` Jens Axboe @ 2003-11-09 14:56 ` Tobias Diedrich 2003-11-12 16:06 ` Tobias Diedrich 0 siblings, 1 reply; 4+ messages in thread From: Tobias Diedrich @ 2003-11-09 14:56 UTC (permalink / raw) To: Jens Axboe; +Cc: linux-kernel As it seems Attila did not write a follow up, I had a look at his patch and the problem. The following patch fixes it for me (Plextor PX-32TS). Please CC me on replies, I am not subscribed to the list. --- linux-2.4.22/include/linux/cdrom.h 2003-10-28 01:30:34.000000000 +0100 +++ linux/include/linux/cdrom.h 2003-11-09 15:44:20.000000000 +0100 @@ -743,7 +743,8 @@ char name[20]; /* name of the device type */ /* per-device flags */ __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */ - __u8 reserved : 6; /* not used yet */ + __u8 use_read10 : 1; /* Use READ10 instead of READCD */ + __u8 reserved : 5; /* not used yet */ struct cdrom_write_settings write; }; --- linux-2.4.22/drivers/cdrom/cdrom.c 2003-11-07 23:46:49.000000000 +0100 +++ linux/drivers/cdrom/cdrom.c 2003-11-09 15:52:14.000000000 +0100 @@ -1400,6 +1400,8 @@ return 0; } +static int cdrom_switch_blocksize(struct cdrom_device_info *cdi, int size); + /* * Specific READ_10 interface */ @@ -1408,6 +1410,7 @@ int blocksize, int nblocks) { struct cdrom_device_ops *cdo = cdi->ops; + int ret = 0; memset(&cgc->cmd, 0, sizeof(cgc->cmd)); cgc->cmd[0] = GPCMD_READ_10; @@ -1419,7 +1422,22 @@ cgc->cmd[7] = (nblocks >> 8) & 0xff; cgc->cmd[8] = nblocks & 0xff; cgc->buflen = blocksize * nblocks; - return cdo->generic_packet(cdi, cgc); + + if (blocksize != CD_FRAMESIZE) { + ret = cdrom_switch_blocksize(cdi, blocksize); + ret |= cdo->generic_packet(cdi, cgc); + ret |= cdrom_switch_blocksize(cdi, CD_FRAMESIZE); + } else ret = cdo->generic_packet(cdi, cgc); + + /* + * Switch cdrom_read_block back to default behaviour + * if we get an error. + * FIXME: Maybe this should not be done on all errors. + */ + if (ret != 0) + cdi->use_read10 = 0; + + return ret; } /* very generic interface for reading the various types of blocks */ @@ -1428,8 +1446,15 @@ int lba, int nblocks, int format, int blksize) { struct cdrom_device_ops *cdo = cdi->ops; + int ret; + + if (cdi->use_read10) + return cdrom_read_cd(cdi, cgc, lba, blksize, nblocks); memset(&cgc->cmd, 0, sizeof(cgc->cmd)); + /* + * SCSI-II devices are not required to support READ_CD. + */ cgc->cmd[0] = GPCMD_READ_CD; /* expected sector size - cdda,mode1,etc. */ cgc->cmd[1] = format << 2; @@ -1452,7 +1477,15 @@ default : cgc->cmd[9] = 0x10; } - return cdo->generic_packet(cdi, cgc); + ret = cdo->generic_packet(cdi, cgc); + if (ret && cgc->sense && cgc->sense->sense_key==0x05 && cgc->sense->asc==0x20 && cgc->sense->ascq==0x00) { + ret = cdrom_read_cd(cdi, cgc, lba, blksize, nblocks); + if (ret == 0) { + cdi->use_read10 = 1; + printk(KERN_INFO "cdrom.c: drive does not like READ_CD for blksize=%d, switching to READ_10.\n", blksize); + } + } + return ret; } /* Just about every imaginable ioctl is supported in the Uniform layer @@ -1956,20 +1989,6 @@ cgc.sense = &sense; cgc.data_direction = CGC_DATA_READ; ret = cdrom_read_block(cdi, &cgc, lba, 1, format, blocksize); - if (ret && sense.sense_key==0x05 && sense.asc==0x20 && sense.ascq==0x00) { - /* - * SCSI-II devices are not required to support - * READ_CD, so let's try switching block size - */ - /* FIXME: switch back again... */ - if ((ret = cdrom_switch_blocksize(cdi, blocksize))) { - kfree(cgc.buffer); - return ret; - } - cgc.sense = NULL; - ret = cdrom_read_cd(cdi, &cgc, lba, blocksize, 1); - ret |= cdrom_switch_blocksize(cdi, blocksize); - } if (!ret && copy_to_user((char *)arg, cgc.buffer, blocksize)) ret = -EFAULT; kfree(cgc.buffer); -- Tobias PGP: http://9ac7e0bc.2ya.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cdrom blocksize reset bug with 2.4.x kernels 2003-11-09 14:56 ` Tobias Diedrich @ 2003-11-12 16:06 ` Tobias Diedrich 0 siblings, 0 replies; 4+ messages in thread From: Tobias Diedrich @ 2003-11-12 16:06 UTC (permalink / raw) To: linux-kernel; +Cc: Jens Axboe, marcelo No comments on this? I wrote: > As it seems Attila did not write a follow up, I had a look at his patch > and the problem. The following patch fixes it for me (Plextor PX-32TS). > > Please CC me on replies, I am not subscribed to the list. > > --- linux-2.4.22/include/linux/cdrom.h 2003-10-28 01:30:34.000000000 +0100 > +++ linux/include/linux/cdrom.h 2003-11-09 15:44:20.000000000 +0100 > @@ -743,7 +743,8 @@ > char name[20]; /* name of the device type */ > /* per-device flags */ > __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */ > - __u8 reserved : 6; /* not used yet */ > + __u8 use_read10 : 1; /* Use READ10 instead of READCD */ > + __u8 reserved : 5; /* not used yet */ > struct cdrom_write_settings write; > }; > > --- linux-2.4.22/drivers/cdrom/cdrom.c 2003-11-07 23:46:49.000000000 +0100 > +++ linux/drivers/cdrom/cdrom.c 2003-11-09 15:52:14.000000000 +0100 > @@ -1400,6 +1400,8 @@ > return 0; > } > > +static int cdrom_switch_blocksize(struct cdrom_device_info *cdi, int size); > + > /* > * Specific READ_10 interface > */ > @@ -1408,6 +1410,7 @@ > int blocksize, int nblocks) > { > struct cdrom_device_ops *cdo = cdi->ops; > + int ret = 0; > > memset(&cgc->cmd, 0, sizeof(cgc->cmd)); > cgc->cmd[0] = GPCMD_READ_10; > @@ -1419,7 +1422,22 @@ > cgc->cmd[7] = (nblocks >> 8) & 0xff; > cgc->cmd[8] = nblocks & 0xff; > cgc->buflen = blocksize * nblocks; > - return cdo->generic_packet(cdi, cgc); > + > + if (blocksize != CD_FRAMESIZE) { > + ret = cdrom_switch_blocksize(cdi, blocksize); > + ret |= cdo->generic_packet(cdi, cgc); > + ret |= cdrom_switch_blocksize(cdi, CD_FRAMESIZE); > + } else ret = cdo->generic_packet(cdi, cgc); > + > + /* > + * Switch cdrom_read_block back to default behaviour > + * if we get an error. > + * FIXME: Maybe this should not be done on all errors. > + */ > + if (ret != 0) > + cdi->use_read10 = 0; > + > + return ret; > } > > /* very generic interface for reading the various types of blocks */ > @@ -1428,8 +1446,15 @@ > int lba, int nblocks, int format, int blksize) > { > struct cdrom_device_ops *cdo = cdi->ops; > + int ret; > + > + if (cdi->use_read10) > + return cdrom_read_cd(cdi, cgc, lba, blksize, nblocks); > > memset(&cgc->cmd, 0, sizeof(cgc->cmd)); > + /* > + * SCSI-II devices are not required to support READ_CD. > + */ > cgc->cmd[0] = GPCMD_READ_CD; > /* expected sector size - cdda,mode1,etc. */ > cgc->cmd[1] = format << 2; > @@ -1452,7 +1477,15 @@ > default : cgc->cmd[9] = 0x10; > } > > - return cdo->generic_packet(cdi, cgc); > + ret = cdo->generic_packet(cdi, cgc); > + if (ret && cgc->sense && cgc->sense->sense_key==0x05 && cgc->sense->asc==0x20 && cgc->sense->ascq==0x00) { > + ret = cdrom_read_cd(cdi, cgc, lba, blksize, nblocks); > + if (ret == 0) { > + cdi->use_read10 = 1; > + printk(KERN_INFO "cdrom.c: drive does not like READ_CD for blksize=%d, switching to READ_10.\n", blksize); > + } > + } > + return ret; > } > > /* Just about every imaginable ioctl is supported in the Uniform layer > @@ -1956,20 +1989,6 @@ > cgc.sense = &sense; > cgc.data_direction = CGC_DATA_READ; > ret = cdrom_read_block(cdi, &cgc, lba, 1, format, blocksize); > - if (ret && sense.sense_key==0x05 && sense.asc==0x20 && sense.ascq==0x00) { > - /* > - * SCSI-II devices are not required to support > - * READ_CD, so let's try switching block size > - */ > - /* FIXME: switch back again... */ > - if ((ret = cdrom_switch_blocksize(cdi, blocksize))) { > - kfree(cgc.buffer); > - return ret; > - } > - cgc.sense = NULL; > - ret = cdrom_read_cd(cdi, &cgc, lba, blocksize, 1); > - ret |= cdrom_switch_blocksize(cdi, blocksize); > - } > if (!ret && copy_to_user((char *)arg, cgc.buffer, blocksize)) > ret = -EFAULT; > kfree(cgc.buffer); > > -- > Tobias PGP: http://9ac7e0bc.2ya.com -- Tobias PGP: http://9ac7e0bc.2ya.com This mail is made of 100% recycled bits. np: ROUND TABLE featuring Nino: Let Me With You 03 - AudioTrack 03 [] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-11-12 16:06 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-07-01 22:25 cdrom blocksize reset bug with 2.4.x kernels Attila Kinali 2003-07-02 11:18 ` Jens Axboe 2003-11-09 14:56 ` Tobias Diedrich 2003-11-12 16:06 ` Tobias Diedrich
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).