handle_nolinux.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //go:build !linux && !windows
  2. /*
  3. Copyright The containerd Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package fifo
  15. import (
  16. "fmt"
  17. "syscall"
  18. )
  19. type handle struct {
  20. fn string
  21. dev uint64
  22. ino uint64
  23. }
  24. func getHandle(fn string) (*handle, error) {
  25. var stat syscall.Stat_t
  26. if err := syscall.Stat(fn, &stat); err != nil {
  27. return nil, fmt.Errorf("failed to stat %v: %w", fn, err)
  28. }
  29. h := &handle{
  30. fn: fn,
  31. dev: uint64(stat.Dev), //nolint:unconvert,nolintlint
  32. ino: uint64(stat.Ino), //nolint:unconvert,nolintlint
  33. }
  34. return h, nil
  35. }
  36. func (h *handle) Path() (string, error) {
  37. var stat syscall.Stat_t
  38. if err := syscall.Stat(h.fn, &stat); err != nil {
  39. return "", fmt.Errorf("path %v could not be statted: %w", h.fn, err)
  40. }
  41. if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint:unconvert,nolintlint
  42. return "", fmt.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
  43. }
  44. return h.fn, nil
  45. }
  46. func (h *handle) Name() string {
  47. return h.fn
  48. }
  49. func (h *handle) Close() error {
  50. return nil
  51. }