ioctl in python

Angus MacKay amackay at starvision.com
Wed Jun 30 15:43:48 EDT 1999


well it seems I have sort of solved my problem. if I use a
string for the 3rd arg then it works properly:
>>> fo=open('/tmp')
>>> fcntl.ioctl(fo.fileno(), 0x80047601, "hi")
'\001\000'
>>> fo=open('/')
>>> fcntl.ioctl(fo.fileno(), 0x80047601, "hi")
'\000\000'
>>> fo=open('/proc')
>>> fcntl.ioctl(fo.fileno(), 0x80047601, "hi")
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: (25, 'Inappropriate ioctl for device')

the question is why? it will still fail with only 2 args or an int:
>>> fcntl.ioctl(fo.fileno(), 0x80047601)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: (14, 'Bad address')
>>> fcntl.ioctl(fo.fileno(), 0x80047601, 1)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: (14, 'Bad address')

cheers, Angus.

Angus MacKay wrote:
> 
> is there some magic to the fcntl.ioctl() call?
> 
> I can do these ioctl calls in C no problem (with a small wrapper):
> (amackay at phat)~/tmp$ ./ioctltest /tmp 0x80047601
> 0x80047601: 1
> (amackay at phat)~/tmp$ ./ioctltest / 0x80047601
> 0x80047601: 0
> (amackay at phat)~/tmp$ ./ioctltest /proc 0x80047601
> /proc: Inappropriate ioctl for device
> 
> that was the Linux ioctl for EXT2 version.
> 
> but in python:
> >>> a = 0
> >>> req = 0x80047601
> >>> import fcntl
> >>> fo=open('/tmp')
> >>> fcntl.ioctl(fo.fileno(), req, a)
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> IOError: (14, 'Bad address')
> >>>




More information about the Python-list mailing list