title: Linux ioctl command is changing between userspace and kernel space
body: <p>Not sure if anyone has any ideas here, I haven't seen this before. I'm writing a stub to test out my kernel module, when I check the value of the command in userspace I get a different value vs. when I take a look at the in kernel space.</p>
  
  <p>Part of the stub:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/stat.h&gt;
  #include "ain.h"
  #include "ain_ioctl.h"
  #define AI_DEVICE   "/dev/ain"
  
  void main()
  {
      int fd, error, ioctl_par = 0;
      char* dev;
      long ret;
  
      dev = AI_DEVICE;
  
      printf("Starting driver test\n");
  
      fd = open(dev, O_RDWR);
      if (fd &lt; 0) {
      /* Failed to open -&gt; Print error-message and exit */
      printf("%s failed to open, error: %s\n", dev, strerror(errno));
      }
  
      printf("Doing the IOCTL now... cmd: %d\n", AIN_IOC_GET_AN0_CONF);
      fflush(stdout);
  
      ret = ioctl(fd, AIN_IOC_GET_AN0_CONF, &amp;ioctl_par);
  </code></pre>
  
  <p>The ain_ioctl.h file:</p>
  
  <pre><code>#define AIN_IOC_MAGIC  'e'
  #define AIN_IOC_GET_AN0_CONF    _IOR(AIN_IOC_MAGIC, 46, int)
  </code></pre>
  
  <p>The ioctl routine in the kernel:</p>
  
  <pre><code>int ain_ioctl (struct inode * inodep, struct file * filp, unsigned int cmd, unsigned long arg)
  {
      printk("In the ain_ioctl function, cmd: %d. type: %d, dir: %d, nr: %d, size: %d\n", 
          cmd, _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
  
      printk("Testing against command: %d. type: %d, dir: %d, nr: %d, size: %d\n",
          AIN_IOC_GET_AN0_CONF, _IOC_TYPE(AIN_IOC_GET_AN0_CONF), _IOC_DIR(AIN_IOC_GET_AN0_CONF), 
          _IOC_NR(AIN_IOC_GET_AN0_CONF), _IOC_SIZE(AIN_IOC_GET_AN0_CONF));
  </code></pre>
  
  <p>Now I would have expected identical output in the user space print as in the kernel. And in the first set of prints in the kernel to the second. However that's not what I'm seeing...</p>
  
  <p>Output:</p>
  
  <pre><code>mike@linux-4puc:~&gt; ./a.out 
  Starting driver test
  Doing the IOCTL now... cmd: -2147195602
  
  mike@linux-4puc:~&gt; dmesg | tail
  [75253.205136] In the ain_ioctl function, cmd: -1078168112. type: 117, dir: 2, nr: 208, size: 16316
  [75253.205140] Testing against            cmd: -2147195602. type: 101, dir: 2, nr: 46, size: 4
  </code></pre>
  
  <p>Anyone have any ideas on why my command is acting differently when I pass it to the kernel via the ioctl command vs when I just check the values by hard coding them (as I am doing in my prints)?</p>
  
  <p>The only warnings I'm seeing when I build seem nothing to do with the ioctl calls:</p>
  
  <pre><code>makedepend: warning: ignoring option -Wall 
  makedepend: warning: ignoring option -Wall 
  makedepend: warning: ain.c (reading /usr/src/linux/include/linux/compiler-gcc.h), line 94: incomplete include == "#include gcc_header(__GNUC__)" 
  makedepend: warning: ain.c (reading /usr/src/linux/include/linux/string.h, line 13): cannot find include file "stdarg.h" 
  </code></pre>
  
  <p>Thanks.</p>