...

Source file src/github.com/Microsoft/hcsshim/internal/guest/linux/ioctl.go

Documentation: github.com/Microsoft/hcsshim/internal/guest/linux

     1  //go:build linux
     2  // +build linux
     3  
     4  package linux
     5  
     6  import (
     7  	"os"
     8  	"unsafe"
     9  
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  // 32 bits to describe an ioctl:
    14  // 0-7:   NR (command for a given ioctl type)
    15  // 8-15:  TYPE (ioctl type)
    16  // 16-29: SIZE (payload size)
    17  // 30-31: DIR (direction of ioctl, can be: none/write/read/write-read)
    18  const (
    19  	IocWrite    = 1
    20  	IocRead     = 2
    21  	IocNRBits   = 8
    22  	IocTypeBits = 8
    23  	IocSizeBits = 14
    24  	IocDirBits  = 2
    25  
    26  	IocNRMask    = (1 << IocNRBits) - 1
    27  	IocTypeMask  = (1 << IocTypeBits) - 1
    28  	IocSizeMask  = (1 << IocSizeBits) - 1
    29  	IocDirMask   = (1 << IocDirBits) - 1
    30  	IocTypeShift = IocNRBits
    31  	IocSizeShift = IocTypeShift + IocTypeBits
    32  	IocDirShift  = IocSizeShift + IocSizeBits
    33  	IocWRBase    = (IocRead | IocWrite) << IocDirShift
    34  )
    35  
    36  // Ioctl makes a syscall described by `command` with data `dataPtr` to device
    37  // driver file `f`.
    38  func Ioctl(f *os.File, command int, dataPtr unsafe.Pointer) error {
    39  	if _, _, err := unix.Syscall(
    40  		unix.SYS_IOCTL,
    41  		f.Fd(),
    42  		uintptr(command),
    43  		uintptr(dataPtr),
    44  	); err != 0 {
    45  		return err
    46  	}
    47  	return nil
    48  }
    49  

View as plain text