2017-03-29 20:55:42 -04:00
|
|
|
// +build linux,cgo
|
2015-12-14 17:16:34 -05:00
|
|
|
|
|
|
|
package loopback
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2017-05-23 10:22:32 -04:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2015-12-14 17:16:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
2017-07-17 04:36:56 -04:00
|
|
|
index, err := unix.IoctlGetInt(int(fd), LoopCtlGetFree)
|
|
|
|
if err != nil {
|
2015-12-14 17:16:34 -05:00
|
|
|
return 0, err
|
|
|
|
}
|
2017-07-17 04:36:56 -04:00
|
|
|
return index, nil
|
2015-12-14 17:16:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
2017-09-11 14:55:05 -04:00
|
|
|
return unix.IoctlSetInt(int(loopFd), LoopSetFd, int(sparseFd))
|
2015-12-14 17:16:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error {
|
2017-05-23 10:22:32 -04:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
2015-12-14 17:16:34 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopClrFd(loopFd uintptr) error {
|
2017-05-23 10:22:32 -04:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopClrFd, 0); err != 0 {
|
2015-12-14 17:16:34 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) {
|
|
|
|
loopInfo := &loopInfo64{}
|
|
|
|
|
2017-05-23 10:22:32 -04:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
2015-12-14 17:16:34 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return loopInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
2017-09-11 14:55:05 -04:00
|
|
|
return unix.IoctlSetInt(int(loopFd), LoopSetCapacity, value)
|
2015-12-14 17:16:34 -05:00
|
|
|
}
|