2021-08-23 13:14:53 +00:00
|
|
|
//go:build linux
|
2019-08-09 13:38:32 +00:00
|
|
|
// +build linux
|
2015-12-14 22:16:34 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package loopback // import "github.com/docker/docker/pkg/loopback"
|
2015-12-14 22:16:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2017-05-23 14:22:32 +00:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2015-12-14 22:16:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
2019-04-22 01:38:40 +00: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 22:16:34 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
2019-04-22 01:38:40 +00:00
|
|
|
return int(ioctlReturn), nil
|
2015-12-14 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
2019-08-09 13:38:32 +00:00
|
|
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_FD, int(sparseFd))
|
2015-12-14 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 13:38:32 +00:00
|
|
|
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *unix.LoopInfo64) error {
|
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_SET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
2015-12-14 22:16:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopClrFd(loopFd uintptr) error {
|
2019-08-09 13:38:32 +00:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_CLR_FD, 0); err != 0 {
|
2015-12-14 22:16:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:38:32 +00:00
|
|
|
func ioctlLoopGetStatus64(loopFd uintptr) (*unix.LoopInfo64, error) {
|
|
|
|
loopInfo := &unix.LoopInfo64{}
|
2015-12-14 22:16:34 +00:00
|
|
|
|
2019-08-09 13:38:32 +00:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_GET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
2015-12-14 22:16:34 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return loopInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
2019-08-09 13:38:32 +00:00
|
|
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_CAPACITY, value)
|
2015-12-14 22:16:34 +00:00
|
|
|
}
|