-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioctl.go
More file actions
59 lines (50 loc) · 1.04 KB
/
ioctl.go
File metadata and controls
59 lines (50 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build linux
package kernelbinder
// ioctlDirection represents the direction bits of an ioctl request code.
type ioctlDirection uintptr
// ioctl direction bits.
const (
iocNone ioctlDirection = 0
iocWrite ioctlDirection = 1
iocRead ioctlDirection = 2
)
// ioctl field widths and shifts.
const (
iocNRBits = 8
iocTypeBits = 8
iocSizeBits = 14
iocDirBits = 2
iocNRShift = 0
iocTypeShift = iocNRShift + iocNRBits // 8
iocSizeShift = iocTypeShift + iocTypeBits // 16
iocDirShift = iocSizeShift + iocSizeBits // 30
)
func ioc(
dir ioctlDirection,
typ uintptr,
nr uintptr,
size uintptr,
) uintptr {
return (uintptr(dir) << iocDirShift) | (typ << iocTypeShift) | (nr << iocNRShift) | (size << iocSizeShift)
}
func iow(
typ uintptr,
nr uintptr,
size uintptr,
) uintptr {
return ioc(iocWrite, typ, nr, size)
}
func ior(
typ uintptr,
nr uintptr,
size uintptr,
) uintptr {
return ioc(iocRead, typ, nr, size)
}
func iowr(
typ uintptr,
nr uintptr,
size uintptr,
) uintptr {
return ioc(iocRead|iocWrite, typ, nr, size)
}