title: How to IOCTL properly from golang
body: <p>I am trying to port bit of <a href="https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/vcmailbox/vcmailbox.c" rel="nofollow noreferrer">raspberrypi's userspace</a> code from C to golang and I've run into a program involving <code>ioctl()</code>. </p>
  
  <p>I am having trouble specifically with following C code</p>
  
  <pre><code>#define MAJOR_NUM 100
  #define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  static int mbox_property(int file_desc, void *buf){
  
     int ret_val = ioctl(file_desc, IOCTL_MBOX_PROPERTY, buf);
     return ret_val;
  }
  </code></pre>
  
  <p>and my go equivalent for this is</p>
  
  <pre><code>func mBoxProperty(f *os.File, buf [256]int64) {
          err := Ioctl(f.Fd(), IOWR(100, 0, 8), uintptr(unsafe.Pointer(&amp;buf[0])))
  
          if err != nil {
                  log.Fatalln("mBoxProperty() : ", err)
          }
  
  }
  
  func Ioctl(fd, op, arg uintptr) error {
          _, _, ep := syscall.Syscall(syscall.SYS_IOCTL, fd, op, arg)
          if ep != 0 {
                  return syscall.Errno(ep)
          }
          return nil
  }
  
  func IOWR(t, nr, size uintptr) uintptr {
          return IOC(IocRead|IocWrite, t, nr, size)
  }
  func IOC(dir, t, nr, size uintptr) uintptr {
          return (dir &lt;&lt; IocDirshift) | (t &lt;&lt; IocTypeshift) | (nr &lt;&lt; IocNrshift) | (size &lt;&lt; IocSizeshift)
  }
  </code></pre>
  
  <p>but whenever I run this, I get <code>invalid argument</code> error, I think it might be due how I am calling the <code>IOCTL()</code> but I am not sure, how can I fix this?</p>