github.com/reds/docker@v1.11.2-rc1/pkg/loopback/ioctl.go (about)

     1  // +build linux
     2  
     3  package loopback
     4  
     5  import (
     6  	"syscall"
     7  	"unsafe"
     8  )
     9  
    10  func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
    11  	index, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, LoopCtlGetFree, 0)
    12  	if err != 0 {
    13  		return 0, err
    14  	}
    15  	return int(index), nil
    16  }
    17  
    18  func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
    19  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetFd, sparseFd); err != 0 {
    20  		return err
    21  	}
    22  	return nil
    23  }
    24  
    25  func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error {
    26  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
    27  		return err
    28  	}
    29  	return nil
    30  }
    31  
    32  func ioctlLoopClrFd(loopFd uintptr) error {
    33  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopClrFd, 0); err != 0 {
    34  		return err
    35  	}
    36  	return nil
    37  }
    38  
    39  func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) {
    40  	loopInfo := &loopInfo64{}
    41  
    42  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
    43  		return nil, err
    44  	}
    45  	return loopInfo, nil
    46  }
    47  
    48  func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
    49  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetCapacity, uintptr(value)); err != 0 {
    50  		return err
    51  	}
    52  	return nil
    53  }