1
2
3
4
5 package unix
6
7 import (
8 "unsafe"
9 )
10
11
12
13
14 func IoctlRetInt(fd int, req uint) (int, error) {
15 ret, _, err := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), 0)
16 if err != 0 {
17 return 0, err
18 }
19 return int(ret), nil
20 }
21
22 func IoctlGetUint32(fd int, req uint) (uint32, error) {
23 var value uint32
24 err := ioctlPtr(fd, req, unsafe.Pointer(&value))
25 return value, err
26 }
27
28 func IoctlGetRTCTime(fd int) (*RTCTime, error) {
29 var value RTCTime
30 err := ioctlPtr(fd, RTC_RD_TIME, unsafe.Pointer(&value))
31 return &value, err
32 }
33
34 func IoctlSetRTCTime(fd int, value *RTCTime) error {
35 return ioctlPtr(fd, RTC_SET_TIME, unsafe.Pointer(value))
36 }
37
38 func IoctlGetRTCWkAlrm(fd int) (*RTCWkAlrm, error) {
39 var value RTCWkAlrm
40 err := ioctlPtr(fd, RTC_WKALM_RD, unsafe.Pointer(&value))
41 return &value, err
42 }
43
44 func IoctlSetRTCWkAlrm(fd int, value *RTCWkAlrm) error {
45 return ioctlPtr(fd, RTC_WKALM_SET, unsafe.Pointer(value))
46 }
47
48
49
50 func IoctlGetEthtoolDrvinfo(fd int, ifname string) (*EthtoolDrvinfo, error) {
51 ifr, err := NewIfreq(ifname)
52 if err != nil {
53 return nil, err
54 }
55
56 value := EthtoolDrvinfo{Cmd: ETHTOOL_GDRVINFO}
57 ifrd := ifr.withData(unsafe.Pointer(&value))
58
59 err = ioctlIfreqData(fd, SIOCETHTOOL, &ifrd)
60 return &value, err
61 }
62
63
64
65
66 func IoctlGetWatchdogInfo(fd int) (*WatchdogInfo, error) {
67 var value WatchdogInfo
68 err := ioctlPtr(fd, WDIOC_GETSUPPORT, unsafe.Pointer(&value))
69 return &value, err
70 }
71
72
73
74
75 func IoctlWatchdogKeepalive(fd int) error {
76
77 return ioctl(fd, WDIOC_KEEPALIVE, 0)
78 }
79
80
81
82
83 func IoctlFileCloneRange(destFd int, value *FileCloneRange) error {
84 return ioctlPtr(destFd, FICLONERANGE, unsafe.Pointer(value))
85 }
86
87
88
89
90 func IoctlFileClone(destFd, srcFd int) error {
91 return ioctl(destFd, FICLONE, uintptr(srcFd))
92 }
93
94 type FileDedupeRange struct {
95 Src_offset uint64
96 Src_length uint64
97 Reserved1 uint16
98 Reserved2 uint32
99 Info []FileDedupeRangeInfo
100 }
101
102 type FileDedupeRangeInfo struct {
103 Dest_fd int64
104 Dest_offset uint64
105 Bytes_deduped uint64
106 Status int32
107 Reserved uint32
108 }
109
110
111
112
113
114 func IoctlFileDedupeRange(srcFd int, value *FileDedupeRange) error {
115 buf := make([]byte, SizeofRawFileDedupeRange+
116 len(value.Info)*SizeofRawFileDedupeRangeInfo)
117 rawrange := (*RawFileDedupeRange)(unsafe.Pointer(&buf[0]))
118 rawrange.Src_offset = value.Src_offset
119 rawrange.Src_length = value.Src_length
120 rawrange.Dest_count = uint16(len(value.Info))
121 rawrange.Reserved1 = value.Reserved1
122 rawrange.Reserved2 = value.Reserved2
123
124 for i := range value.Info {
125 rawinfo := (*RawFileDedupeRangeInfo)(unsafe.Pointer(
126 uintptr(unsafe.Pointer(&buf[0])) + uintptr(SizeofRawFileDedupeRange) +
127 uintptr(i*SizeofRawFileDedupeRangeInfo)))
128 rawinfo.Dest_fd = value.Info[i].Dest_fd
129 rawinfo.Dest_offset = value.Info[i].Dest_offset
130 rawinfo.Bytes_deduped = value.Info[i].Bytes_deduped
131 rawinfo.Status = value.Info[i].Status
132 rawinfo.Reserved = value.Info[i].Reserved
133 }
134
135 err := ioctlPtr(srcFd, FIDEDUPERANGE, unsafe.Pointer(&buf[0]))
136
137
138 for i := range value.Info {
139 rawinfo := (*RawFileDedupeRangeInfo)(unsafe.Pointer(
140 uintptr(unsafe.Pointer(&buf[0])) + uintptr(SizeofRawFileDedupeRange) +
141 uintptr(i*SizeofRawFileDedupeRangeInfo)))
142 value.Info[i].Dest_fd = rawinfo.Dest_fd
143 value.Info[i].Dest_offset = rawinfo.Dest_offset
144 value.Info[i].Bytes_deduped = rawinfo.Bytes_deduped
145 value.Info[i].Status = rawinfo.Status
146 value.Info[i].Reserved = rawinfo.Reserved
147 }
148
149 return err
150 }
151
152 func IoctlHIDGetDesc(fd int, value *HIDRawReportDescriptor) error {
153 return ioctlPtr(fd, HIDIOCGRDESC, unsafe.Pointer(value))
154 }
155
156 func IoctlHIDGetRawInfo(fd int) (*HIDRawDevInfo, error) {
157 var value HIDRawDevInfo
158 err := ioctlPtr(fd, HIDIOCGRAWINFO, unsafe.Pointer(&value))
159 return &value, err
160 }
161
162 func IoctlHIDGetRawName(fd int) (string, error) {
163 var value [_HIDIOCGRAWNAME_LEN]byte
164 err := ioctlPtr(fd, _HIDIOCGRAWNAME, unsafe.Pointer(&value[0]))
165 return ByteSliceToString(value[:]), err
166 }
167
168 func IoctlHIDGetRawPhys(fd int) (string, error) {
169 var value [_HIDIOCGRAWPHYS_LEN]byte
170 err := ioctlPtr(fd, _HIDIOCGRAWPHYS, unsafe.Pointer(&value[0]))
171 return ByteSliceToString(value[:]), err
172 }
173
174 func IoctlHIDGetRawUniq(fd int) (string, error) {
175 var value [_HIDIOCGRAWUNIQ_LEN]byte
176 err := ioctlPtr(fd, _HIDIOCGRAWUNIQ, unsafe.Pointer(&value[0]))
177 return ByteSliceToString(value[:]), err
178 }
179
180
181
182 func IoctlIfreq(fd int, req uint, value *Ifreq) error {
183
184
185 return ioctlPtr(fd, req, unsafe.Pointer(&value.raw))
186 }
187
188
189
190
191
192 func ioctlIfreqData(fd int, req uint, value *ifreqData) error {
193
194
195 return ioctlPtr(fd, req, unsafe.Pointer(value))
196 }
197
View as plain text