c9e4e4f741
Unlike the FUSE implementation on Linux, macFUSE doesn't cache the file attributes from the `LOOKUP` call, so it calls `GETATTR` prior to accessing a file. In the case of the `VirtualConfNode` (reverse config file passthrough), this resulted in the default `GETATTR` implementation returning an empty result, ultimately resulting in a "permission denied" error. 14:44:14.095207 rx 3: GETATTR n2 14:44:14.095229 tx 3: OK, {tA=1s {M0100000 SZ=0 L=0 0:0 0 0:8954996 A 0.000000 M 0.000000 C 0.000000}} 14:44:14.099943 rx 4: ACCESS n2 {u=501 g=20 r} 14:44:14.099990 tx 4: 13=permission denied By impementing `Getattr` (from `fs.NodeGetattrer`) on `VirtualConfNode` this solves the issue.
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package fusefrontend_reverse
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"syscall"
|
|
|
|
"github.com/hanwen/go-fuse/v2/fs"
|
|
"github.com/hanwen/go-fuse/v2/fuse"
|
|
)
|
|
|
|
var _ = (fs.NodeOpener)((*VirtualConfNode)(nil))
|
|
var _ = (fs.NodeGetattrer)((*VirtualConfNode)(nil))
|
|
|
|
type VirtualConfNode struct {
|
|
fs.Inode
|
|
|
|
path string
|
|
}
|
|
|
|
func (n *VirtualConfNode) Open(ctx context.Context, flags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
|
|
fd, err := syscall.Open(n.path, syscall.O_RDONLY, 0)
|
|
if err != nil {
|
|
errno = fs.ToErrno(err)
|
|
return
|
|
}
|
|
fh = &VirtualConfFile{fd: fd}
|
|
return
|
|
}
|
|
|
|
func (n *VirtualConfNode) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
|
var st syscall.Stat_t
|
|
err := syscall.Stat(n.path, &st)
|
|
if err != nil {
|
|
return fs.ToErrno(err)
|
|
}
|
|
out.FromStat(&st)
|
|
return 0
|
|
}
|
|
|
|
|
|
// Check that we have implemented the fs.File* interfaces
|
|
var _ = (fs.FileReader)((*VirtualConfFile)(nil))
|
|
var _ = (fs.FileReleaser)((*VirtualConfFile)(nil))
|
|
|
|
type VirtualConfFile struct {
|
|
mu sync.Mutex
|
|
fd int
|
|
}
|
|
|
|
func (f *VirtualConfFile) Read(ctx context.Context, buf []byte, off int64) (res fuse.ReadResult, errno syscall.Errno) {
|
|
f.mu.Lock()
|
|
defer f.mu.Unlock()
|
|
res = fuse.ReadResultFd(uintptr(f.fd), off, len(buf))
|
|
return
|
|
}
|
|
|
|
func (f *VirtualConfFile) Release(ctx context.Context) syscall.Errno {
|
|
f.mu.Lock()
|
|
defer f.mu.Unlock()
|
|
if f.fd != -1 {
|
|
err := syscall.Close(f.fd)
|
|
f.fd = -1
|
|
return fs.ToErrno(err)
|
|
}
|
|
return syscall.EBADF
|
|
}
|