github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/pkg/ipmi/ioctl_unix.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Bits and pieces from asm-generic/ioctl.h
     6  package ipmi
     7  
     8  import (
     9  	"syscall"
    10  	"unsafe"
    11  )
    12  
    13  const (
    14  	_IOC_WRITE = 0x1
    15  	_IOC_READ  = 0x2
    16  
    17  	_IOC_NRBITS   = 8
    18  	_IOC_TYPEBITS = 8
    19  	_IOC_SIZEBITS = 14
    20  	_IOC_NRSHIFT  = 0
    21  
    22  	_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
    23  	_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
    24  	_IOC_DIRSHIFT  = _IOC_SIZESHIFT + _IOC_SIZEBITS
    25  )
    26  
    27  func ioc(dir int, t int, nr int, size int) int {
    28  	return (dir << _IOC_DIRSHIFT) | (t << _IOC_TYPESHIFT) |
    29  		(nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT)
    30  }
    31  
    32  func ior(t int, nr int, size int) int {
    33  	return ioc(_IOC_READ, t, nr, size)
    34  }
    35  
    36  func iowr(t int, nr int, size int) int {
    37  	return ioc(_IOC_READ|_IOC_WRITE, t, nr, size)
    38  }
    39  
    40  func ioctl(fd uintptr, name int, data unsafe.Pointer) syscall.Errno {
    41  	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(name), uintptr(data))
    42  	return err
    43  }