2021-08-23 09:14:53 -04:00
|
|
|
//go:build linux
|
2019-08-09 09:38:32 -04:00
|
|
|
// +build linux
|
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 {
|
2019-08-09 09:38:32 -04:00
|
|
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_FD, int(sparseFd))
|
2015-12-14 17:16:34 -05:00
|
|
|
}
|
|
|
|
|
2019-08-09 09:38:32 -04: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 17:16:34 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctlLoopClrFd(loopFd uintptr) error {
|
2019-08-09 09:38:32 -04:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_CLR_FD, 0); err != 0 {
|
2015-12-14 17:16:34 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-09 09:38:32 -04:00
|
|
|
func ioctlLoopGetStatus64(loopFd uintptr) (*unix.LoopInfo64, error) {
|
|
|
|
loopInfo := &unix.LoopInfo64{}
|
2015-12-14 17:16:34 -05:00
|
|
|
|
2019-08-09 09:38:32 -04:00
|
|
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_GET_STATUS64, 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 {
|
2019-08-09 09:38:32 -04:00
|
|
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_CAPACITY, value)
|
2015-12-14 17:16:34 -05:00
|
|
|
}
|