New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhanced ioctl #46964
Comments
IIUC, current ioctl is not capable of handling arbitrary argument 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): 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) |
Can you please be a bit more explicit? What limitation do you see in |
On Monday 28 April 2008, Martin v. Löwis wrote:
In the example I gave, the ioctl passes a structure: class eos_dl_args_t (Structure):
_fields_ = [("length", c_ulong),
("data", c_void_p)] AFAIK, there is no way to do that with fcntl.ioctl, is there? |
Passing structures is certainly possible. I'd try args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value)
fcntl.ioctl(fd, request, args) Alternatively, args = eos_dl_args_t()
...
args_p = cast(pointer(args), c_void_ptr).value
fcntl.ioctl(fd, request, args_p) should also work, IIUC. |
On Monday 28 April 2008, Martin v. Löwis wrote:
You are correct, both of the above work (at least on x86) |
So, should we close this? |
I think we should close it. |
OK. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: