ndbecker2 at gmail.com
Sat Apr 26 12:53:45 CEST 2008
Gabriel Genellina wrote:
> En Fri, 25 Apr 2008 09:30:56 -0300, Neal Becker <ndbecker2 at gmail.com>
>> 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
>> 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."""
> 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
Here is what ioctl should be:
from ctypes import *
libc = CDLL ('/lib/libc.so.6')
libc.ioctl.argtypes = (c_int, c_int, POINTER (eos_dl_args_t))
_IOC_WRITE = 0x1
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