github.com/torfuzx/docker@v1.8.1/pkg/devicemapper/ioctl.go (about)

     1  // +build linux
     2  
     3  package devicemapper
     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  }
    54  
    55  func ioctlBlkGetSize64(fd uintptr) (int64, error) {
    56  	var size int64
    57  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, BlkGetSize64, uintptr(unsafe.Pointer(&size))); err != 0 {
    58  		return 0, err
    59  	}
    60  	return size, nil
    61  }
    62  
    63  func ioctlBlkDiscard(fd uintptr, offset, length uint64) error {
    64  	var r [2]uint64
    65  	r[0] = offset
    66  	r[1] = length
    67  
    68  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, BlkDiscard, uintptr(unsafe.Pointer(&r[0]))); err != 0 {
    69  		return err
    70  	}
    71  	return nil
    72  }