Note that there are some explanatory texts on larger screens.

plurals
  1. POpython - could ioctl numbers differs from C ioctl numbers?
    primarykey
    data
    text
    <p>As far as I know, ioctl numbers are well defined by the drivers and registered in the kernel.</p> <p>I was playing with some code in python for querying joystick states. I have read <a href="http://www.kernel.org/doc/Documentation/input/joystick-api.txt" rel="nofollow">this doc about joystick api</a>, <a href="http://www.mjmwired.net/kernel/Documentation/ioctl-number.txt" rel="nofollow">this doc about ioctl numbers</a>, and <a href="http://docs.python.org/library/fcntl.html" rel="nofollow">this one from python fcntl module</a>.</p> <p>I've created a C program for testing and querying values, and the python tests with code that I took <a href="http://www.hsg-kl.de/faecher/inf/material/bonsai/util/ppdev.py" rel="nofollow">from here</a> for implementing the <code>_IOR()</code> C macro.</p> <h2>Kernel driver define:</h2> <pre><code>monolith@monolith ~/temp $ grep JSIOCGAXES /usr/include/* -r /usr/include/linux/joystick.h:#define JSIOCGAXES _IOR('j', 0x11, __u8) </code></pre> <h2>C program</h2> <pre><code>#include &lt;stdio.h&gt; #include &lt;linux/joystick.h&gt; #include &lt;fcntl.h&gt; int main() { int fd = open("/dev/input/js0", O_RDONLY); printf("Ioctl Number: (int)%d (hex)%x\n", JSIOCGAXES, JSIOCGAXES); char number; ioctl(fd, JSIOCGAXES, &amp;number); printf("Number of axes: %d\n", number); close(fd); return 0; } </code></pre> <h2>C program Output:</h2> <pre><code>monolith@monolith ~/temp $ ./test Ioctl Number: (int)-2147390959 (hex)80016a11 Number of axes: 6 </code></pre> <h2>Python output</h2> <pre><code># check if _IOR results in the used ioctl number in C &gt;&gt;&gt; _IOR(ord('j'), 0x11, 'c') -2147390959 &gt;&gt;&gt; file = open("/dev/input/js0") # use that integer &gt;&gt;&gt; fcntl.ioctl(file, -2147390959) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; IOError: [Errno 14] Bad address # ask what hex value is &gt;&gt;&gt; "%x" % -2147390959 '-7ffe95ef' # WHY THIS HEX CONVERSION DIFFERS? &gt;&gt;&gt; fcntl.ioctl(file, -0x7ffe95ef) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; IOError: [Errno 14] Bad address # Use the hex value from the C program output &gt;&gt;&gt; fcntl.ioctl(file, 0x80016a11) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; IOError: [Errno 14] Bad address </code></pre> <p>Any ideas why I can't query the file descriptor with that ioctl number? <code>ioctl()</code> and <code>fcntl()</code> functions take a file descriptor or an object with the <code>fileno()</code> method implemented so I discart the error from the <code>file</code> object.</p> <p>Maybe the problem comes with number conversion and types, no idea...clues?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload