ioctl in python
Angus MacKay
amackay at starvision.com
Wed Jun 30 20:06:38 EDT 1999
hun?
why is this expecting a 4 byte buffer? my C version uses an int*
and it works no problem.
as for 80 being a input I think you have it backwards (for linux-i386 at least):
0x80046601 EXT2_IOC_GETFLAGS int *
0x40046602 EXT2_IOC_SETFLAGS const int *
0x80047601 EXT2_IOC_GETVERSION int *
0x40047602 EXT2_IOC_SETVERSION const int *
cheers, Angus.
Perry Faulkner wrote:
>
> Hi Angus,
>
> The ioctl cmd code (0x80047601) is expecting a 4 byte buffer to be
> passed to it. The
> simplest thing is something like :
>
> rec = pack('BBBB', 0,0,0,0)
> or
> rec = pack('L', 0)
>
> depending on what's expected, then
>
> ioctl(handle, 0x80047601, rec)
>
> By the way, the 80 part of the command also says this is an input
> function, so you
> are writing the data, rec in this case! For an output function you would
> follow the
> ioctl with an unpack of the data buffer, as well. But you still need to
> supply the
> packed input buffer in any case.
>
> Hope this helps!
>
> Regards,
> Perry
>
> Angus MacKay wrote:
>
> > 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