github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/pkg/loopback/ioctl.go (about) 1 //go:build linux 2 // +build linux 3 4 package loopback // import "github.com/docker/docker/pkg/loopback" 5 6 import ( 7 "unsafe" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 func ioctlLoopCtlGetFree(fd uintptr) (int, error) { 13 // The ioctl interface for /dev/loop-control (since Linux 3.1) is a bit 14 // off compared to what you'd expect: instead of writing an integer to a 15 // parameter pointer like unix.IoctlGetInt() expects, it returns the first 16 // available loop device index directly. 17 ioctlReturn, _, err := unix.Syscall(unix.SYS_IOCTL, fd, LoopCtlGetFree, 0) 18 if err != 0 { 19 return 0, err 20 } 21 return int(ioctlReturn), nil 22 } 23 24 func ioctlLoopSetFd(loopFd, sparseFd uintptr) error { 25 return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_FD, int(sparseFd)) 26 } 27 28 func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *unix.LoopInfo64) error { 29 if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_SET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 { 30 return err 31 } 32 return nil 33 } 34 35 func ioctlLoopClrFd(loopFd uintptr) error { 36 if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_CLR_FD, 0); err != 0 { 37 return err 38 } 39 return nil 40 } 41 42 func ioctlLoopGetStatus64(loopFd uintptr) (*unix.LoopInfo64, error) { 43 loopInfo := &unix.LoopInfo64{} 44 45 if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_GET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 { 46 return nil, err 47 } 48 return loopInfo, nil 49 } 50 51 func ioctlLoopSetCapacity(loopFd uintptr, value int) error { 52 return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_CAPACITY, value) 53 }