title: ioctl - invalid argument
body: <p>I  have  </p>
  
  <pre><code>#define IOCTL_ALLOC_MSG _IO(MAJOR_NUM, 0) 
  #define IOCTL_DEALLOC_MSG _IO(MAJOR_NUM, 1)
  </code></pre>
  
  <p>in a header file.</p>
  
  <p>and in the driver file I wrote:</p>
  
  <pre><code>struct file_operations memory_fops = {
    unlocked_ioctl: device_ioctl,
    open: memory_open,
    release: memory_release
  };
  
  
  int memory_init(void) {
    int result;
  
    /* Registering device */
    result = register_chrdev(MAJOR_NUM, "memory", &amp;memory_fops);
    if (result &lt; 0) {
      printk("&lt;1&gt;memory: cannot obtain major number %d\n", MAJOR_NUM);
      return result;
    }
  
    allocfunc();
  
    printk("&lt;1&gt;Inserting memory module\n");
    return 0;
  
  }
  
  int device_ioctl(struct inode *inode,   /* see include/linux/fs.h */
           struct file *file, /* ditto */
           unsigned int ioctl_num,    /* number and param for ioctl */
           unsigned long ioctl_param)
  {
      /* 
       * Switch according to the ioctl called 
       */
      printk ( "&lt;l&gt; inside ioctl \n" );
      switch (ioctl_num) {
      case IOCTL_ALLOC_MSG:
          allocfunc();
          break;
      case IOCTL_DEALLOC_MSG:
          deallocfunc();
          break;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I created the character file like </p>
  
  <pre><code>mknod /dev/memory c 60 0
  </code></pre>
  
  <p>the app call fails</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      FILE * memfile;
  
      /* Opening the device parlelport */
      memfile=fopen("memory","r+");
      if ( memfile &lt;0) {
          printf ( " cant open file \n");
          return -1;
      }
  
      /* We remove the buffer from the file i/o */
      int ret_val;
      if ( argc &gt; 1 ) {
          if ( strcmp (argv[1], "mem" ) ==0 ) {
  
  
              ret_val = ioctl(memfile, IOCTL_ALLOC_MSG);
  
              if (ret_val &lt; 0) {
                  printf("ioctl failed. Return code: %d, meaning: %s\n", ret_val, strerror(errno));
                  return -1;
              }
          }
  </code></pre>
  
  <p>when i run the app i get "ioctl failed. Return code: -1, meaning: Invalid argument" in : strerror(errno)</p>
  
  <p>printk:</p>
  
  <pre><code>Inserting memory module
  </code></pre>
  
  <p>fyi, I experimented with "/dev/memory" "memory" different names and major number combinations - but in vain.</p>