I am trying to port bit of raspberrypi's userspace code from C to golang and I've run into a program involving ioctl()
.
I am having trouble specifically with following C 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;
}
and my go equivalent for this is
func mBoxProperty(f *os.File, buf [256]int64) {
err := Ioctl(f.Fd(), IOWR(100, 0, 8), uintptr(unsafe.Pointer(&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 << IocDirshift) | (t << IocTypeshift) | (nr << IocNrshift) | (size << IocSizeshift)
}
but whenever I run this, I get invalid argument
error, I think it might be due how I am calling the IOCTL()
but I am not sure, how can I fix this?