ioctl

Allan Christian Long acl3k at agate.cs.Virginia.EDU
Thu May 23 07:56:51 AEST 1991


In article <105553 at sgi.sgi.com> rpw3 at sgi.com (Rob Warnock) writes:
>In article <1991May21.224750.535 at murdoch.acc.Virginia.EDU>
>acl3k at agate.cs.Virginia.EDU (Allan Christian Long) writes:
>+---------------
>| an ioctl call is giving me an "Invalid argument error".  The
>| call looks like this:
>| 
>| 	if (ioctl(trackerPtr->fileDescriptor, FIONREAD, &charsToRead) < 0)
>| 
>| The first parameter is a file descriptor and the third is a pointer to
>| a long.  FIONREAD is a parameter from the termio.h file.  I have RTFM'ed
>| until I'm blue in the face, but I can't find FIONREAD mentioned anywhere
>| in any of the manuals.  The SunOS manual has a page on "filio" that
>| describes this parameter, but there is no filio page for IRIX.
>+---------------
>
>In /usr/include/sys/ioctl.h, one finds:
>
>	#define FIONREAD _IOR(f, 127, int)      /* get # bytes to read */
>
>Sadly, this is about all that exists. The rest does indeed seem to have
>fallen between the cracks. (*sigh*) It should be in at least *one* of
>ioctl(2), fcntl(2), socket(2), termio(7), or streamio(7), but isn't.
>
>And the comment in ioctl.h is even a bit misleading. Well, the SunOS
>filio(2) man page should be good enough. FIONREAD is the same on all
>systems I know of -- that support it, that is, not all do. It returns
>the number of bytes immediately available for reading (i.e., without
>blocking) from the file descriptor. In Irix, it *should* work on plain
>files, pipes, sockets, and terminal devices (TTYs and PTYs). What kind
>of device is "trackerPtr->fileDescriptor"? If it's a special 3rd-party
>beast, perhaps the Irix device driver doesn't support FIONREAD...
>

I wrote the worlds simplest ioctl program that just opens a file and
does ioctl(fildes, FIONREAD, &numChars) on it (where fildes and numChars
are defined appropriately).  I tried it on regular terminals and it gave
error 22, which is EINVAL -- "Request or the third argument is not valid
for this device." (quoting from the ioctl man page)  The device that I
really want to be able to use this on is a Polhemus 3D tracker hooked up
to a serial port.  I've been hooking it up to port 2 and using device
/dev/ttyd2.
	Is there any other way to find out how many bytes there are
to read from a serial line?

>
>-Rob
>
>p.s. I just checked, and on Irix 3.3.2, FIONREAD is not supported on
>pipes or plain files. You get errno=25. Weird. (Bug?)
>Mountain View, CA  94039-7311

If it makes any difference, I'm running this on a 4D/310 VGX running
IRIX 3.3.2.

	Thanks.


A. Chris Long, Jr.			acl3k at virginia.edu



More information about the Comp.sys.sgi mailing list