ioctl.py
Neal Becker
ndbecker2 at gmail.com
Sat Apr 26 06:53:45 EDT 2008
Gabriel Genellina wrote:
> En Fri, 25 Apr 2008 09:30:56 -0300, Neal Becker <ndbecker2 at gmail.com>
> escribió:
>
>> I need an ioctl call equivalent to this C code:
>>
>> my_struct s;
>> s.p = p; << a pointer to an array of char
>> s.image_size = image_size;
>> return (ioctl(fd, xxx, &s));
>>
>> I'm thinking to use python array for the array of char, but I don't see
>> how
>> to put it's address into the structure.
>
> Use the array's buffer_info() method:
> """buffer_info(): Return a tuple (address, length) giving the current
> memory address and the length in elements of the buffer used to hold
> array's contents."""
> <http://docs.python.org/lib/module-array.html>
> and you can use the struct module to build my_struct.
>
>> Maybe ctypes is the answer?
>
> It could be used too, but I think that in this case it's harder to use
> ctypes.
>
Here is what ioctl should be:
from ctypes import *
libc = CDLL ('/lib/libc.so.6')
#print libc.ioctl
libc.ioctl.argtypes = (c_int, c_int, POINTER (eos_dl_args_t))
_IOC_WRITE = 0x1
_IOC_NRBITS= 8
_IOC_TYPEBITS= 8
_IOC_SIZEBITS= 14
_IOC_DIRBITS= 2
_IOC_NRSHIFT= 0
_IOC_TYPESHIFT= (_IOC_NRSHIFT+_IOC_NRBITS)
_IOC_SIZESHIFT= (_IOC_TYPESHIFT+_IOC_TYPEBITS)
_IOC_DIRSHIFT= (_IOC_SIZESHIFT+_IOC_SIZEBITS)
def _IOC (dir, type, nr, size):
return (((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
def ioctl (fd, request, args):
return libc.ioctl (fd, request, args)
More information about the Python-list
mailing list