public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* SG_IO open flags are which
@ 2003-12-15 16:39 Pat LaVarre
  2003-12-18  3:41 ` Douglas Gilbert
  0 siblings, 1 reply; 5+ messages in thread
From: Pat LaVarre @ 2003-12-15 16:39 UTC (permalink / raw)
  To: dougg; +Cc: linux-scsi

Doug G:

What open flags should apps use to talk SG_IO?

O_RDWR?  O_RDONLY?  O_NONBLOCK?  Other?  Combination?

Wrong info in Google includes:

> List: linux-scsi
> Date: 2003-12-03 0:17:56
> Re: sg utils sg_io -i 0x24 -y "12 00:00:00 24 00"
> ...
> > > - O_RDWR
> > > + O_RDONLY|O_NONBLOCK
> > ... not from reading a document anywhere ...
> ...
> Possibly we recommend open O_NONBLOCK for SG_IO ...
> Evidence in favour ... includes ...
> From: linux-2.6.0-test11/Documentation/cdrom/cdrom-standard.tex
> ...
> 1997/12/28 ... propose ... $O_NONBLOCK$ to indicate
> that the device is opened just for issuing $ioctl$
> commands.

Wrong guess, if we try 2.6.0-test11 with the three commands:

-i x24 -y "12 00:00:00 24 00" // standard Inquiry
-y "1B 00:00:00 00 00" // Stop Unit
-y "1B 00:00:00 01 00" // Start Unit

Either open O_NONBLOCK or open O_RDWR allows pass thru of standard
Inquiry.  And open O_RDWR allows pass thru of Stop Unit.  But open
O_NONBLOCK rejects pass thru of Stop Unit:

$ sudo plscsi /dev/sg0 -x "1B 00:00:00 00 00"
...
$ grep -i 'Operation not permitted' /usr/include/asm/errno.h
#define EPERM            1      /* Operation not permitted */
$

Perhaps lk has no open that allows all of SG_IO without closing trays,
spinning up discs, etc.?  If we do face that limit, then often we can
settle for O_NONBLOCK to list device names (e.g. sg_scan) and O_RDWR
otherwise (e.g. sg_dd).

Wish I knew where in the lk source we're choosing to have the privilege
of the open vary the transparency of the pass thru.

Pat LaVarre



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: SG_IO open flags are which
@ 2004-04-06  0:49 Pat LaVarre
  0 siblings, 0 replies; 5+ messages in thread
From: Pat LaVarre @ 2004-04-06  0:49 UTC (permalink / raw)
  To: dougg; +Cc: linux-scsi

Doug G:

> > Re: SG_IO open flags are which
> > http://marc.theaimsgroup.com/?t=107150658300002
> > ...
> > So first try and open() with the (O_NONBLOCK
> > | O_RDWR) flags.  If that yields ENOMEDIUM
> > look for the corresponding sg device name.
> > If the initial open() yields EROFS or EACESS
> > then try to open it (O_NONBLOCK | O_RDONLY).
> > ...

Clear workarounds for three possible results, yes, thank you.

Naturally I fear uncertainly and doubt the effects of defaulting to
O_RDWR or O_RDONLY.

> > Confused enough yet :-)

I can confirm ioctl SG_IO op x2A, in Linux-2.6.5, passes:

thru open O_NONBLOCK of mountable /dev/scd$n, and
thru open (O_NONBLOCK | O_RDWR) of unmountable /dev/sg$n, but
NOT thru open O_NONBLOCK of unmountable /dev/sg$n.

I get these same results no matter disc absent or present.

Next steps may include:

a) Contrast PDT x05 ioctl CDROM_SEND_PACKET with ioctl SG_IO.

b) Trace when open/ close implies op x1E "PREVENT" "ALLOW" around ioctl,
even ioctl of op x1B "START" "STOP" Eject.

Pat LaVarre



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: SG_IO open flags are which
@ 2004-05-20 15:16 Pat LaVarre
  0 siblings, 0 replies; 5+ messages in thread
From: Pat LaVarre @ 2004-05-20 15:16 UTC (permalink / raw)
  To: linux-scsi

Recently I saw yet another newbie trip over the ioctl 
CDROM_SEND_PACKET/ SG_IO dialectic that:

1) open /dev/scd$n /dev/hd$v maybe inflict less undesirable side 
effects if we open O_NONBLOCK

2) open /dev/sg$n maybe inflict less undesirable side effects if we 
open O_RDWR | O_NONBLOCK

I'm replying again in this thread only because I don't remember before 
now seeing that dialectic nutshelled so pointedly.

Looks like ioctl SCSI pass thru apps should string-compare the device 
name to decide default open flags.  Over the years, that's potentially 
insanely fragile, but I guess it will work out ok for Linux 2.6/ 2.4.

Pat LaVarre


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

end of thread, other threads:[~2004-05-20 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-15 16:39 SG_IO open flags are which Pat LaVarre
2003-12-18  3:41 ` Douglas Gilbert
2003-12-18  9:47   ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2004-04-06  0:49 Pat LaVarre
2004-05-20 15: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