ioctl problem
Donn Cave
donn at u.washington.edu
Thu Feb 15 13:04:56 EST 2001
Quoth "Eduardo Ferro" <eferro at inicia.es>:
| Have anybody some example of the use of ioctl method when this ioctl
| return some data in a estructure.
| I use icotl to control the cdrom, and the ioctls without parameters works
| well, but i don`t know how to use the ioctls that return me data
>>> import fcntl
>>> print fcntl.ioctl.__doc__
ioctl(fd, opt, [arg])
Perform the requested operation on file descriptor fd. The operation
is defined by op and is operating system dependent. Typically these
codes can be retrieved from the library module IOCTL. The argument arg
is optional, and defaults to 0; it may be an int or a string. If arg is
given as a string, the return value of ioctl is a string of that length,
containing the resulting value put in the arg buffer by the operating system.
The length of the arg string is not allowed to exceed 1024 bytes. If the arg
given is an integer or if none is specified, the result value is an integer
corresponding to the return value of the ioctl call in the C code.
That means you must lay your data out as a string of bytes. Pass any
string of that length to ioctl(), then use the "struct" module's byte
unpacking functions to convert the return string to the data type you
want to work with.
>>> import fcntl
>>> n = fcntl.ioctl(0, 1074295912, 'XXXXXXXX')
>>> n
'\030\000P\000\360\000 \003'
>>> import struct
>>> struct.unpack('hhhh', n)
(24, 80, 240, 800)
That's the TIOCGWINSZ ioctl (on NetBSD 1.5.)
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list