Debian Codegraph @

linux/gioctl/ioctl.go

raw symbols SCIP
1 package gioctl
2
3 import (
4 "syscall"
5 )
6
7 const (
8 numberBits = 8
9 typeBits = 8
10
11 numberShift = 0
12 typeShift = numberShift + numberBits
13 sizeShift = typeShift + typeBits
14 directionShift = sizeShift + sizeBits
15 )
16
17 func ioc(dir, t, nr, size uintptr) uintptr {
18 return (dir << directionShift) | (t << typeShift) | (nr << numberShift) | (size << sizeShift)
19 }
20
21 // Io used for a simple ioctl that sends nothing but the type and number, and receives back nothing but an (integer) retval.
22 func Io(t, nr uintptr) uintptr {
23 return ioc(directionNone, t, nr, 0)
24 }
25
26 // IoR used for an ioctl that reads data from the device driver. The driver will be allowed to return sizeof(data_type) bytes to the user.
27 func IoR(t, nr, size uintptr) uintptr {
28 return ioc(directionRead, t, nr, size)
29 }
30
31 // IoW used for an ioctl that writes data to the device driver.
32 func IoW(t, nr, size uintptr) uintptr {
33 return ioc(directionWrite, t, nr, size)
34 }
35
36 // IoRW a combination of IoR and IoW. That is, data is both written to the driver and then read back from the driver by the client.
37 func IoRW(t, nr, size uintptr) uintptr {
38 return ioc(directionRead|directionWrite, t, nr, size)
39 }
40
41 // Ioctl simplified ioct call
42 func Ioctl(fd, op, arg uintptr) error {
43 _, _, ep := syscall.Syscall(syscall.SYS_IOCTL, fd, op, arg)
44 if ep != 0 {
45 return syscall.Errno(ep)
46 }
47 return nil
48 }