Linux SCSI subsystem development
 help / color / mirror / Atom feed
* /dev/hd* in sg_scan
@ 2003-10-28  0:09 Pat LaVarre
  2003-10-29  4:35 ` Douglas Gilbert
  0 siblings, 1 reply; 3+ messages in thread
From: Pat LaVarre @ 2003-10-28  0:09 UTC (permalink / raw)
  To: linux-scsi

> http://tldp.org/HOWTO/SCSI-Generic-HOWTO/open.html
> ... O_NONBLOCK ... ignored by ioctl(SG_IO)

As of 2.6, in fact we now need O_NONBLOCK if we want open O_RDONLY to
let us talk SG_IO to a DVD/CD with no disk present?  Also we discard the
history of passing thru less commands for O_RDONLY than for O_RDWR?

Reaching those conclusions inspired me to try the following trivial
inline patch for sg3_utils-1.05/sg_scan.c.  I see this patch brings much
of /dev/hd* to the notice of sg utils sg_scan.  However, this patch may
not be ready for prime-time, some of the code I flowed around I do not
understand.

Do we intend to make /dev/hd[a-z] available for passing ioctl SG_IO thru
to ATAPI DVD/CD, in 2.6?  Or for 2.6 do we recommend ab/using some other
device name?

Patched sg_scan success here looks like:

$ sudo sg_scan -i
/dev/hda: scsi0 channel=0 id=0 lun=0
/dev/hdc: scsi0 channel=0 id=0 lun=0 [em]
    LITE-ON   COMBO LTC-48161H  KH0K [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]  type=5
    Iomega    RRD               01.U [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
$

Perhaps the soft bridge from SCSI to ATA HDD in Linux, like some
FireWire HDD, is an apparently SCSI device that does not support op x12
Inquiry.

Pat LaVarre

P.S. Before now I see no hits in:

http://groups.google.com/groups?q=sg_scan+dev+hdc

diff -Nur sg3_utils-1.05/sg_scan.c sg3_utils/sg_scan.c
--- sg3_utils-1.05/sg_scan.c	2003-05-29 02:55:48.000000000 -0600
+++ sg3_utils/sg_scan.c	2003-10-27 16:55:09.085283256 -0700
@@ -43,6 +43,8 @@
 
 #define NUMERIC_SCAN_DEF 1   /* change to 0 to make alpha scan default */
 
+#define DEV_HD_SCAN 26 /* change to 4 to scan only /dev/hd[abcd] */
+
 #define OFF sizeof(struct sg_header)
 #define INQ_REPLY_LEN 96        /* logic assumes >= sizeof(inqCmdBlk) */
 #define INQ_CMD_LEN 6
@@ -101,6 +103,14 @@
     char buff[64];
     int  big,little;
 
+    if (0 <= k) {
+            if (k < DEV_HD_SCAN) {
+                sprintf(fname, "/dev/hd%c", ('a' + k));
+                return;
+            }
+            k -= DEV_HD_SCAN;
+    }
+
     strcpy(fname, "/dev/sg");
     if (do_numeric) {
         sprintf(buff, "%d", k);
@@ -202,8 +212,10 @@
             }
             else if ((ENODEV == errno) || (ENOENT == errno) ||
                      (ENXIO == errno)) {
-                ++num_errors;
-                ++num_silent;
+                if (DEV_HD_SCAN <= k) {
+                    ++num_errors;
+                    ++num_silent;
+                }
                 continue;
             }
             else {
@@ -216,7 +228,7 @@
             }
         }
         res = ioctl(sg_fd, SCSI_IOCTL_GET_IDLUN, &my_idlun);
-        if (res < 0) {
+        if ((res < 0) && (DEV_HD_SCAN <= k)) {
             snprintf(ebuff, EBUFF_SZ,
                      ME "device %s failed on scsi ioctl, skip", fname);
             perror(ebuff);
@@ -224,7 +236,7 @@
             continue;
         }
         res = ioctl(sg_fd, SCSI_IOCTL_GET_BUS_NUMBER, &host_no);
-        if (res < 0) {
+        if ((res < 0) && (DEV_HD_SCAN <= k)) {
             snprintf(ebuff, EBUFF_SZ, ME "device %s failed on scsi "
                      "ioctl(2), skip", fname);
             perror(ebuff);
@@ -233,7 +245,7 @@
         }
 #ifdef SG_EMULATED_HOST
         res = ioctl(sg_fd, SG_EMULATED_HOST, &emul);
-        if (res < 0) {
+        if ((res < 0) && (DEV_HD_SCAN <= k)) {
             snprintf(ebuff, EBUFF_SZ, 
                      ME "device %s failed on sg ioctl(3), skip", fname);
             perror(ebuff);
@@ -252,7 +264,9 @@
         printf(", huid=%d", my_idlun.host_unique_id);
 #endif
 #ifdef SG_GET_RESERVED_SIZE
-        {
+        if (k < DEV_HD_SCAN) {
+            printf("\n");
+        } else {
             My_sg_scsi_id m_id; /* compatible with sg_scsi_id_t in sg.h */
 
             res = ioctl(sg_fd, SG_GET_SCSI_ID, &m_id);
@@ -282,6 +296,9 @@
             continue;
         }
 #endif
+        if (k < DEV_HD_SCAN) {
+            continue;
+        }
         memset(isghp, 0, sizeof(struct sg_header));
         isghp->reply_len = inqOutLen;
         memcpy(inqBuff + OFF, inqCmdBlk, INQ_CMD_LEN);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: /dev/hd* in sg_scan
  2003-10-28  0:09 /dev/hd* in sg_scan Pat LaVarre
@ 2003-10-29  4:35 ` Douglas Gilbert
  2003-10-29 17:16   ` Pat LaVarre
  0 siblings, 1 reply; 3+ messages in thread
From: Douglas Gilbert @ 2003-10-29  4:35 UTC (permalink / raw)
  To: Pat LaVarre; +Cc: linux-scsi

Pat LaVarre wrote:
>>http://tldp.org/HOWTO/SCSI-Generic-HOWTO/open.html
>>... O_NONBLOCK ... ignored by ioctl(SG_IO)
> 
> 
> As of 2.6, in fact we now need O_NONBLOCK if we want open O_RDONLY to
> let us talk SG_IO to a DVD/CD with no disk present?  Also we discard the
> history of passing thru less commands for O_RDONLY than for O_RDWR?
> 
> Reaching those conclusions inspired me to try the following trivial
> inline patch for sg3_utils-1.05/sg_scan.c.  I see this patch brings much
> of /dev/hd* to the notice of sg utils sg_scan.  However, this patch may
> not be ready for prime-time, some of the code I flowed around I do not
> understand.
> 
> Do we intend to make /dev/hd[a-z] available for passing ioctl SG_IO thru
> to ATAPI DVD/CD, in 2.6?  Or for 2.6 do we recommend ab/using some other
> device name?
> 
> Patched sg_scan success here looks like:
> 
> $ sudo sg_scan -i
> /dev/hda: scsi0 channel=0 id=0 lun=0
> /dev/hdc: scsi0 channel=0 id=0 lun=0 [em]
>     LITE-ON   COMBO LTC-48161H  KH0K [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
> /dev/sg0: scsi0 channel=0 id=0 lun=0 [em]  type=5
>     Iomega    RRD               01.U [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
> $
> 
> Perhaps the soft bridge from SCSI to ATA HDD in Linux, like some
> FireWire HDD, is an apparently SCSI device that does not support op x12
> Inquiry.

Pat,
Sg3_utils' sg_map and sg_scan for lk 2.6 still have me
thinking (and waiting). Currently sg devices have no
sysfs presence (yes Christoph, I'm still waiting). My
patch to the sg driver to use cdevs (char devices with
sysfs visibility and > 256 minors) seems to fallen foul
of the latest freeze. So scsi tape robots and enclosures
won't have any sysfs visibility.

Now as for /dev/hd and /dev/sd the situation is complex
and probably going to get worse before it get better.
With either /dev/hd and /dev/sd you may soon want to find
out (or probe) before making any assumptions:
   - what protocol are you using (e.g. ATA, ATAPI, SCSI)
   - what transport (e.g. pATA, sATA, SPI, FC, USB, SAS)

Anyways your patch looks interesting and hope to add it
soon (currently I'm rewriting sginfo).

Doug Gilbert


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: /dev/hd* in sg_scan
  2003-10-29  4:35 ` Douglas Gilbert
@ 2003-10-29 17:16   ` Pat LaVarre
  0 siblings, 0 replies; 3+ messages in thread
From: Pat LaVarre @ 2003-10-29 17:16 UTC (permalink / raw)
  To: dougg; +Cc: linux-scsi

> Sg3_utils' sg_map and sg_scan for lk 2.6 still have me
> thinking ... waiting ...
> sg .. to use cdevs (char ... sysfs ... > 256 minors)
> latest freeze ... scsi tape robots and enclosures ...

Prompt & cogent as usual, thank you.

> >http://tldp.org/HOWTO/SCSI-Generic-HOWTO/open.html
> > >... O_NONBLOCK ... ignored by ioctl(SG_IO)
> > 
> > As of 2.6, in fact we now need O_NONBLOCK if we want open O_RDONLY to
> > let us talk SG_IO to a DVD/CD with no disk present?  Also we discard the
> > history of passing thru less commands for O_RDONLY than for O_RDWR?

I guess, but I do not know.

> With either /dev/hd and /dev/sd ...

Thanks for hinting at /dev/sd$v or /dev/sd$v$n.

I see /dev/scd$n rejects SG_IO.

So far I have only seen /dev/hd$v and /dev/sg$n work.

> With either /dev/hd and /dev/sd you may soon want to find
> out (or probe) before making any assumptions:
>    - what protocol are you using (e.g. ATA, ATAPI, SCSI)
>    - what transport (e.g. pATA, sATA, SPI, FC, USB, SAS)

I see you hint darkly ... at what I do not know.

Why am I going to want to discover protocol & transport?

How will I do so?

> currently I'm rewriting sginfo).

Thank you.

I trust you won't let me slow you down with my ignorant questions.

Pat LaVarre



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-10-29 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-28  0:09 /dev/hd* in sg_scan Pat LaVarre
2003-10-29  4:35 ` Douglas Gilbert
2003-10-29 17:16   ` Pat LaVarre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox