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