]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/golang.org/x/sys/unix/syscall_linux.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / golang.org / x / sys / unix / syscall_linux.go
index 84aa8ea03fdf753eb961779337827748659ff7ca..c302f01b2e941a7d82dbf810105dfb3f83caa6fe 100644 (file)
@@ -12,6 +12,9 @@
 package unix
 
 import (
+       "encoding/binary"
+       "net"
+       "runtime"
        "syscall"
        "unsafe"
 )
@@ -36,6 +39,20 @@ func Creat(path string, mode uint32) (fd int, err error) {
        return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
 }
 
+//sys  FanotifyInit(flags uint, event_f_flags uint) (fd int, err error)
+//sys  fanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname *byte) (err error)
+
+func FanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname string) (err error) {
+       if pathname == "" {
+               return fanotifyMark(fd, flags, mask, dirFd, nil)
+       }
+       p, err := BytePtrFromString(pathname)
+       if err != nil {
+               return err
+       }
+       return fanotifyMark(fd, flags, mask, dirFd, p)
+}
+
 //sys  fchmodat(dirfd int, path string, mode uint32) (err error)
 
 func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
@@ -55,6 +72,15 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
 // ioctl itself should not be exposed directly, but additional get/set
 // functions for specific types are permissible.
 
+// IoctlSetPointerInt performs an ioctl operation which sets an
+// integer value on fd, using the specified request number. The ioctl
+// argument is called with a pointer to the integer value, rather than
+// passing the integer value directly.
+func IoctlSetPointerInt(fd int, req uint, value int) error {
+       v := int32(value)
+       return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
+}
+
 // IoctlSetInt performs an ioctl operation which sets an integer value
 // on fd, using the specified request number.
 func IoctlSetInt(fd int, req uint, value int) error {
@@ -69,6 +95,12 @@ func ioctlSetTermios(fd int, req uint, value *Termios) error {
        return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 
+func IoctlSetRTCTime(fd int, value *RTCTime) error {
+       err := ioctl(fd, RTC_SET_TIME, uintptr(unsafe.Pointer(value)))
+       runtime.KeepAlive(value)
+       return err
+}
+
 // IoctlGetInt performs an ioctl operation which gets an integer value
 // from fd, using the specified request number.
 func IoctlGetInt(fd int, req uint) (int, error) {
@@ -89,6 +121,12 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
        return &value, err
 }
 
+func IoctlGetRTCTime(fd int) (*RTCTime, error) {
+       var value RTCTime
+       err := ioctl(fd, RTC_RD_TIME, uintptr(unsafe.Pointer(&value)))
+       return &value, err
+}
+
 //sys  Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
 
 func Link(oldpath string, newpath string) (err error) {
@@ -710,6 +748,51 @@ func (sa *SockaddrXDP) sockaddr() (unsafe.Pointer, _Socklen, error) {
        return unsafe.Pointer(&sa.raw), SizeofSockaddrXDP, nil
 }
 
+// This constant mirrors the #define of PX_PROTO_OE in
+// linux/if_pppox.h. We're defining this by hand here instead of
+// autogenerating through mkerrors.sh because including
+// linux/if_pppox.h causes some declaration conflicts with other
+// includes (linux/if_pppox.h includes linux/in.h, which conflicts
+// with netinet/in.h). Given that we only need a single zero constant
+// out of that file, it's cleaner to just define it by hand here.
+const px_proto_oe = 0
+
+type SockaddrPPPoE struct {
+       SID    uint16
+       Remote net.HardwareAddr
+       Dev    string
+       raw    RawSockaddrPPPoX
+}
+
+func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) {
+       if len(sa.Remote) != 6 {
+               return nil, 0, EINVAL
+       }
+       if len(sa.Dev) > IFNAMSIZ-1 {
+               return nil, 0, EINVAL
+       }
+
+       *(*uint16)(unsafe.Pointer(&sa.raw[0])) = AF_PPPOX
+       // This next field is in host-endian byte order. We can't use the
+       // same unsafe pointer cast as above, because this value is not
+       // 32-bit aligned and some architectures don't allow unaligned
+       // access.
+       //
+       // However, the value of px_proto_oe is 0, so we can use
+       // encoding/binary helpers to write the bytes without worrying
+       // about the ordering.
+       binary.BigEndian.PutUint32(sa.raw[2:6], px_proto_oe)
+       // This field is deliberately big-endian, unlike the previous
+       // one. The kernel expects SID to be in network byte order.
+       binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID)
+       copy(sa.raw[8:14], sa.Remote)
+       for i := 14; i < 14+IFNAMSIZ; i++ {
+               sa.raw[i] = 0
+       }
+       copy(sa.raw[14:], sa.Dev)
+       return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil
+}
+
 func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
        switch rsa.Addr.Family {
        case AF_NETLINK:
@@ -820,6 +903,22 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
                        SharedUmemFD: pp.Shared_umem_fd,
                }
                return sa, nil
+       case AF_PPPOX:
+               pp := (*RawSockaddrPPPoX)(unsafe.Pointer(rsa))
+               if binary.BigEndian.Uint32(pp[2:6]) != px_proto_oe {
+                       return nil, EINVAL
+               }
+               sa := &SockaddrPPPoE{
+                       SID:    binary.BigEndian.Uint16(pp[6:8]),
+                       Remote: net.HardwareAddr(pp[8:14]),
+               }
+               for i := 14; i < 14+IFNAMSIZ; i++ {
+                       if pp[i] == 0 {
+                               sa.Dev = string(pp[14:i])
+                               break
+                       }
+               }
+               return sa, nil
        }
        return nil, EAFNOSUPPORT
 }
@@ -905,10 +1004,50 @@ func GetsockoptString(fd, level, opt int) (string, error) {
        return string(buf[:vallen-1]), nil
 }
 
+func GetsockoptTpacketStats(fd, level, opt int) (*TpacketStats, error) {
+       var value TpacketStats
+       vallen := _Socklen(SizeofTpacketStats)
+       err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
+       return &value, err
+}
+
+func GetsockoptTpacketStatsV3(fd, level, opt int) (*TpacketStatsV3, error) {
+       var value TpacketStatsV3
+       vallen := _Socklen(SizeofTpacketStatsV3)
+       err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
+       return &value, err
+}
+
 func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) {
        return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
 }
 
+func SetsockoptPacketMreq(fd, level, opt int, mreq *PacketMreq) error {
+       return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
+}
+
+// SetsockoptSockFprog attaches a classic BPF or an extended BPF program to a
+// socket to filter incoming packets.  See 'man 7 socket' for usage information.
+func SetsockoptSockFprog(fd, level, opt int, fprog *SockFprog) error {
+       return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog))
+}
+
+func SetsockoptCanRawFilter(fd, level, opt int, filter []CanFilter) error {
+       var p unsafe.Pointer
+       if len(filter) > 0 {
+               p = unsafe.Pointer(&filter[0])
+       }
+       return setsockopt(fd, level, opt, p, uintptr(len(filter)*SizeofCanFilter))
+}
+
+func SetsockoptTpacketReq(fd, level, opt int, tp *TpacketReq) error {
+       return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp))
+}
+
+func SetsockoptTpacketReq3(fd, level, opt int, tp *TpacketReq3) error {
+       return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp))
+}
+
 // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
 
 // KeyctlInt calls keyctl commands in which each argument is an int.
@@ -1288,6 +1427,13 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
        return mount(source, target, fstype, flags, datap)
 }
 
+func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
+       if raceenabled {
+               raceReleaseMerge(unsafe.Pointer(&ioSync))
+       }
+       return sendfile(outfd, infd, offset, count)
+}
+
 // Sendto
 // Recvfrom
 // Socketpair
@@ -1302,6 +1448,7 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
 //sys  Chroot(path string) (err error)
 //sys  ClockGetres(clockid int32, res *Timespec) (err error)
 //sys  ClockGettime(clockid int32, time *Timespec) (err error)
+//sys  ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error)
 //sys  Close(fd int) (err error)
 //sys  CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
 //sys  DeleteModule(name string, flags int) (err error)
@@ -1362,7 +1509,6 @@ func Getpgrp() (pid int) {
 //sys  Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6
 //sys  read(fd int, p []byte) (n int, err error)
 //sys  Removexattr(path string, attr string) (err error)
-//sys  Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
 //sys  Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error)
 //sys  RequestKey(keyType string, description string, callback string, destRingid int) (id int, err error)
 //sys  Setdomainname(p []byte) (err error)
@@ -1387,6 +1533,7 @@ func Setgid(uid int) (err error) {
 
 //sys  Setpriority(which int, who int, prio int) (err error)
 //sys  Setxattr(path string, attr string, data []byte, flags int) (err error)
+//sys  Signalfd(fd int, mask *Sigset_t, flags int) = SYS_SIGNALFD4
 //sys  Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error)
 //sys  Sync()
 //sys  Syncfs(fd int) (err error)
@@ -1431,15 +1578,12 @@ func Munmap(b []byte) (err error) {
 // Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
 // using the specified flags.
 func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
-       n, _, errno := Syscall6(
-               SYS_VMSPLICE,
-               uintptr(fd),
-               uintptr(unsafe.Pointer(&iovs[0])),
-               uintptr(len(iovs)),
-               uintptr(flags),
-               0,
-               0,
-       )
+       var p unsafe.Pointer
+       if len(iovs) > 0 {
+               p = unsafe.Pointer(&iovs[0])
+       }
+
+       n, _, errno := Syscall6(SYS_VMSPLICE, uintptr(fd), uintptr(p), uintptr(len(iovs)), uintptr(flags), 0, 0)
        if errno != 0 {
                return 0, syscall.Errno(errno)
        }
@@ -1518,6 +1662,82 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
        return EACCES
 }
 
+//sys nameToHandleAt(dirFD int, pathname string, fh *fileHandle, mountID *_C_int, flags int) (err error) = SYS_NAME_TO_HANDLE_AT
+//sys openByHandleAt(mountFD int, fh *fileHandle, flags int) (fd int, err error) = SYS_OPEN_BY_HANDLE_AT
+
+// fileHandle is the argument to nameToHandleAt and openByHandleAt. We
+// originally tried to generate it via unix/linux/types.go with "type
+// fileHandle C.struct_file_handle" but that generated empty structs
+// for mips64 and mips64le. Instead, hard code it for now (it's the
+// same everywhere else) until the mips64 generator issue is fixed.
+type fileHandle struct {
+       Bytes uint32
+       Type  int32
+}
+
+// FileHandle represents the C struct file_handle used by
+// name_to_handle_at (see NameToHandleAt) and open_by_handle_at (see
+// OpenByHandleAt).
+type FileHandle struct {
+       *fileHandle
+}
+
+// NewFileHandle constructs a FileHandle.
+func NewFileHandle(handleType int32, handle []byte) FileHandle {
+       const hdrSize = unsafe.Sizeof(fileHandle{})
+       buf := make([]byte, hdrSize+uintptr(len(handle)))
+       copy(buf[hdrSize:], handle)
+       fh := (*fileHandle)(unsafe.Pointer(&buf[0]))
+       fh.Type = handleType
+       fh.Bytes = uint32(len(handle))
+       return FileHandle{fh}
+}
+
+func (fh *FileHandle) Size() int   { return int(fh.fileHandle.Bytes) }
+func (fh *FileHandle) Type() int32 { return fh.fileHandle.Type }
+func (fh *FileHandle) Bytes() []byte {
+       n := fh.Size()
+       if n == 0 {
+               return nil
+       }
+       return (*[1 << 30]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&fh.fileHandle.Type)) + 4))[:n:n]
+}
+
+// NameToHandleAt wraps the name_to_handle_at system call; it obtains
+// a handle for a path name.
+func NameToHandleAt(dirfd int, path string, flags int) (handle FileHandle, mountID int, err error) {
+       var mid _C_int
+       // Try first with a small buffer, assuming the handle will
+       // only be 32 bytes.
+       size := uint32(32 + unsafe.Sizeof(fileHandle{}))
+       didResize := false
+       for {
+               buf := make([]byte, size)
+               fh := (*fileHandle)(unsafe.Pointer(&buf[0]))
+               fh.Bytes = size - uint32(unsafe.Sizeof(fileHandle{}))
+               err = nameToHandleAt(dirfd, path, fh, &mid, flags)
+               if err == EOVERFLOW {
+                       if didResize {
+                               // We shouldn't need to resize more than once
+                               return
+                       }
+                       didResize = true
+                       size = fh.Bytes + uint32(unsafe.Sizeof(fileHandle{}))
+                       continue
+               }
+               if err != nil {
+                       return
+               }
+               return FileHandle{fh}, int(mid), nil
+       }
+}
+
+// OpenByHandleAt wraps the open_by_handle_at system call; it opens a
+// file via a handle as previously returned by NameToHandleAt.
+func OpenByHandleAt(mountFD int, handle FileHandle, flags int) (fd int, err error) {
+       return openByHandleAt(mountFD, handle.fileHandle, flags)
+}
+
 /*
  * Unimplemented
  */
@@ -1606,7 +1826,6 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
 // Shmdt
 // Shmget
 // Sigaltstack
-// Signalfd
 // Swapoff
 // Swapon
 // Sysfs