github.com/zaolin/u-root@v0.0.0-20200428085104-64aaafd46c6d/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_NONE  = 0x0
    15  	_IOC_WRITE = 0x1
    16  	_IOC_READ  = 0x2
    17  
    18  	_IOC_NRBITS   = 8
    19  	_IOC_TYPEBITS = 8
    20  	_IOC_SIZEBITS = 14
    21  	_IOC_NRSHIFT  = 0
    22  
    23  	_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
    24  	_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
    25  	_IOC_DIRSHIFT  = _IOC_SIZESHIFT + _IOC_SIZEBITS
    26  )
    27  
    28  func ioc(dir int, t int, nr int, size int) int {
    29  	return (dir << _IOC_DIRSHIFT) | (t << _IOC_TYPESHIFT) |
    30  		(nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT)
    31  }
    32  
    33  func IO(t int, nr int) int {
    34  	return ioc(_IOC_NONE, t, nr, 0)
    35  }
    36  
    37  func IOR(t int, nr int, size int) int {
    38  	return ioc(_IOC_READ, t, nr, size)
    39  }
    40  
    41  func IOWR(t int, nr int, size int) int {
    42  	return ioc(_IOC_READ|_IOC_WRITE, t, nr, size)
    43  }
    44  
    45  func Ioctl(fd uintptr, name int, data unsafe.Pointer) syscall.Errno {
    46  	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(name), uintptr(data))
    47  	return err
    48  }