public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dougg@torque.net>
To: Matthew Dharm <mdharm-scsi@one-eyed-alien.net>
Cc: James Bottomley <James.Bottomley@SteelEye.com>,
	torvalds@transmeta.com,
	Linux SCSI list <linux-scsi@vger.kernel.org>,
	Greg KH <greg@kroah.com>,
	USB Developers <linux-usb-devel@lists.sourceforge.net>
Subject: Re: PATCH; make sr.c respect use_10_for_ms
Date: Sun, 22 Jun 2003 15:05:02 +1000	[thread overview]
Message-ID: <3EF538FE.3040204@torque.net> (raw)
In-Reply-To: <20030621212406.N2811@one-eyed-alien.net>

Matthew Dharm wrote:
> On Sat, Jun 21, 2003 at 09:54:46PM -0500, James Bottomley wrote:
> 
>>@@ -702,7 +692,7 @@
>> 		printk("%s: scsi-1 drive\n", cd->cdi.name);
>> 		return;
>> 	}
>>-	n = buffer[3] + 4;
>>+	n = rc;
>> 	cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
>> 	cd->readcd_known = 1;
>> 	cd->readcd_cdda = buffer[n + 5] & 0x01;
> 
> 
> This bit isn't right.  n is supposed to point to the start of the page
> data, not the page header.  The header is a different size if the command
> is 6-byte or 10-byte.
> 
> If you look at my patch, you can see the correct offsets you need.

Matt,
Here is a small function to calculate the mode sense reponse
offset to the first page (borrowed from smartmontools, GPL-ed
code):


/* Offset into mode sense (6 or 10 byte) response that actual mode page
  * starts at (relative to resp[0]). Returns -1 if problem */
int scsiModePageOffset(const UINT8 * resp, int len, int modese_10)
{
     int resp_len, bd_len;
     int offset = -1;
 

     if (resp) {
         if (modese_10) {
             resp_len = (resp[0] << 8) + resp[1] + 2;
             bd_len = (resp[6] << 8) + resp[7];
             offset = bd_len + 8;
         } else {
             resp_len = resp[0] + 1;
             bd_len = resp[3];
             offset = bd_len + 4;
         }
         if ((offset + 2) > len) {
             pout("scsiModePageOffset: page too small, offset=%d "
                  "resp_len=%d bd_len=%d\n", offset, resp_len, bd_len);
             offset = -1;
         } else if ((offset + 2) > resp_len) {
             pout("scsiModePageOffset: response length too short, 
resp_len=%d"
                  " offset=%d bd_len=%d\n", resp_len, offset, bd_len);
             offset = -1;
         }
     }
     return offset;
}


BTW The sanity checks can be useful, Recently, I have been
trying to solve problems with the aacraid which returns
garbage to MODE SENSE commands (and locks up when given
LOG SENSE commands).
My USB mass storage enclosure is quirky as well: when
it gets a MODE_SENSE_10 it swaps the response_length bytes
(bytes 0 and 1) producing an exaggerated length. The mode
page is still readable and valid.

Doug Gilbert


  reply	other threads:[~2003-06-22  4:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-21 23:59 PATCH; make sr.c respect use_10_for_ms Matthew Dharm
2003-06-22  0:07 ` Linus Torvalds
2003-06-22  0:12   ` Matthew Dharm
2003-06-22  0:21     ` Linus Torvalds
2003-06-22  0:30       ` Matthew Dharm
2003-06-22  0:38         ` Linus Torvalds
2003-06-22  0:46           ` Matthew Dharm
2003-06-22  0:25 ` James Bottomley
2003-06-22  0:46   ` Matthew Dharm
2003-06-22  2:54     ` James Bottomley
2003-06-22  4:24       ` Matthew Dharm
2003-06-22  5:05         ` Douglas Gilbert [this message]
2003-06-22 13:58         ` James Bottomley
2003-06-22 19:49           ` Matthew Dharm
2003-06-22 19:56             ` Matthew Dharm
2003-06-22 20:37               ` James Bottomley
2003-06-22 21:06                 ` Matthew Dharm
2003-06-23 14:33                   ` James Bottomley
2003-06-23 17:30                     ` Matthew Dharm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3EF538FE.3040204@torque.net \
    --to=dougg@torque.net \
    --cc=James.Bottomley@SteelEye.com \
    --cc=greg@kroah.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=mdharm-scsi@one-eyed-alien.net \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox