...
1
2
3
18
19 package fifo
20
21 import (
22 "fmt"
23 "syscall"
24 )
25
26 type handle struct {
27 fn string
28 dev uint64
29 ino uint64
30 }
31
32 func getHandle(fn string) (*handle, error) {
33 var stat syscall.Stat_t
34 if err := syscall.Stat(fn, &stat); err != nil {
35 return nil, fmt.Errorf("failed to stat %v: %w", fn, err)
36 }
37
38 h := &handle{
39 fn: fn,
40 dev: uint64(stat.Dev),
41 ino: uint64(stat.Ino),
42 }
43
44 return h, nil
45 }
46
47 func (h *handle) Path() (string, error) {
48 var stat syscall.Stat_t
49 if err := syscall.Stat(h.fn, &stat); err != nil {
50 return "", fmt.Errorf("path %v could not be statted: %w", h.fn, err)
51 }
52 if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino {
53 return "", fmt.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
54 }
55 return h.fn, nil
56 }
57
58 func (h *handle) Name() string {
59 return h.fn
60 }
61
62 func (h *handle) Close() error {
63 return nil
64 }
65
View as plain text