unix: add FileHandle, NewFileHandle, NameToHandleAt, OpenByHandleAt

This adds wrappers around name_to_handle_at and open_by_handle_at.

Requires root (or CAP_DAC_READ_SEARCH, rather) to run tests, which at
least some of our builders have.

bradfitz@go:~/src/golang.org/x/sys/unix$ go test -c && sudo ./unix.test -test.run=OpenBy -test.v=true
=== RUN   TestOpenByHandleAt
=== RUN   TestOpenByHandleAt/clone=false
=== RUN   TestOpenByHandleAt/clone=true
--- PASS: TestOpenByHandleAt (0.00s)
    syscall_linux_test.go:546: mountID: 22, handle: size=8, type=1, bytes="\x9e\x1e\b\x00~\x8c\xe5\x9d"
    --- PASS: TestOpenByHandleAt/clone=false (0.00s)
        syscall_linux_test.go:568: opened fd 3
    --- PASS: TestOpenByHandleAt/clone=true (0.00s)
        syscall_linux_test.go:568: opened fd 3
PASS

Fixes golang/go#30537

Change-Id: Ia48a8faab2fee665d88a16d81a3a0c1504b129ce
Reviewed-on: https://go-review.googlesource.com/c/sys/+/173357
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2 files changed
tree: 2ae61a29095122aff47be4e6aec00dfd589273dd
  1. cpu/
  2. plan9/
  3. unix/
  4. windows/
  5. .gitattributes
  6. .gitignore
  7. AUTHORS
  8. codereview.cfg
  9. CONTRIBUTING.md
  10. CONTRIBUTORS
  11. go.mod
  12. LICENSE
  13. PATENTS
  14. README.md
README.md

sys

This repository holds supplemental Go packages for low-level interactions with the operating system.

Download/Install

The easiest way to install is to run go get -u golang.org/x/sys. You can also manually git clone the repository to $GOPATH/src/golang.org/x/sys.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the sys repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.