2017-03-29 20:55:42 -04:00
|
|
|
// +build linux,cgo
|
2015-12-14 17:16:34 -05:00
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package loopback // import "github.com/docker/docker/pkg/loopback"
|
2015-12-14 17:16:34 -05:00
|
|
|
|
|
|
|
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) {
|
2019-04-21 21:38:40 -04:00
|
|
|
// The ioctl interface for /dev/loop-control (since Linux 3.1) is a bit
|
|
|
|
// off compared to what you'd expect: instead of writing an integer to a
|
|
|
|
// parameter pointer like unix.IoctlGetInt() expects, it returns the first
|
|
|
|
// available loop device index directly.
|
|
|
|
ioctlReturn, _, err := unix.Syscall(unix.SYS_IOCTL, fd, LoopCtlGetFree, 0)
|
|
|
|
if err != 0 {
|
2015-12-14 17:16:34 -05:00
|
|
|
return 0, err
|
|
|
|
}
|
2019-04-21 21:38:40 -04:00
|
|
|
return int(ioctlReturn), 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
|
|
|
}
|