[New-bugs-announce] [issue2712] enhanced ioctl
ndbecker
report at bugs.python.org
Mon Apr 28 23:01:21 CEST 2008
New submission from ndbecker <ndbecker2 at gmail.com>:
IIUC, current ioctl is not capable of handling arbitrary argument
types.
This code will allow any arg type (such as structures with pointers to
embedded structures).
The code for _IOC is taken from linux and might not be portable.import
-----
from ctypes import *
libc = CDLL ('/lib/libc.so.6')
#print libc.ioctl
def set_ioctl_argtype (arg_type):
libc.ioctl.argtypes = (c_int, c_int, arg_type)
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)
----
Example (not complete):
class eos_dl_args_t (Structure):
_fields_ = [("length", c_ulong),
("data", c_void_p)]
args = eos_dl_args_t()
args.length = len (c)
args.data = cast (pointer (c), c_void_p)
from eioctl import *
set_ioctl_argtype (POINTER (eos_dl_args_t))
EOS_IOC_MAGIC = 0xF4
request = IOC(IOC_WRITE, EOS_IOC_MAGIC, 0x00, 0) # ignore size
err = ioctl (fd, request, args)
----------
components: Extension Modules
messages: 65933
nosy: ndbecker
severity: normal
status: open
title: enhanced ioctl
type: feature request
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2712>
__________________________________
More information about the New-bugs-announce
mailing list