controller_linux.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package controller
  2. import "gitlab.com/beoran/galago/os/linux"
  3. import "os"
  4. import "unsafe"
  5. import "syscall"
  6. import "fmt"
  7. func Ioctl(file * os.File, code uint32, pointer unsafe.Pointer) error {
  8. fmt.Printf("ioctl: %d %d %d\n", uintptr(file.Fd()), uintptr(code), uintptr(pointer))
  9. _, _, errno := syscall.Syscall(
  10. syscall.SYS_IOCTL,
  11. uintptr(file.Fd()),
  12. uintptr(code),
  13. uintptr(pointer))
  14. if (errno != 0) {
  15. return errno
  16. }
  17. return nil
  18. }
  19. func GetDriverVersion(file * os.File) (int32, error) {
  20. res := int32(0)
  21. data := unsafe.Pointer(&res)
  22. err := Ioctl(file, linux.EVIOCGVERSION, data)
  23. return res, err
  24. }
  25. func GetName(file * os.File) (string, error) {
  26. buffer := [256]byte{}
  27. err := Ioctl(file, linux.EVIOCGNAME(uintptr(len(buffer))), unsafe.Pointer(&buffer))
  28. return string(buffer[0:len(buffer)]), err
  29. }
  30. func GetId(file * os.File) (linux.INPUT_id, error) {
  31. var result linux.INPUT_id
  32. err := Ioctl(file, linux.EVIOCGID, unsafe.Pointer(&result))
  33. return result, err
  34. }