Commit 02a3917c authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: support Access

parent 6217b933
......@@ -102,6 +102,7 @@ type Operations interface {
StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status
Access(ctx context.Context, mask uint32) fuse.Status
// File locking
GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status)
SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status)
......
......@@ -408,7 +408,8 @@ func (b *rawBridge) Readlink(cancel <-chan struct{}, header *fuse.InHeader) (out
}
func (b *rawBridge) Access(cancel <-chan struct{}, input *fuse.AccessIn) (status fuse.Status) {
return fuse.ENOSYS
n, _ := b.inode(input.NodeId, 0)
return n.node.Access(&fuse.Context{Caller: input.Caller, Cancel: cancel}, input.Mask)
}
// Extended attributes.
......
......@@ -227,6 +227,10 @@ func (n *DefaultOperations) RemoveXAttr(ctx context.Context, attr string) fuse.S
return fuse.ENOATTR
}
func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) ListXAttr(ctx context.Context, dest []byte) (uint32, fuse.Status) {
return 0, fuse.OK
}
......
......@@ -6,17 +6,15 @@ package nodefs
import (
"context"
"log"
"os"
"path/filepath"
"sync"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal"
)
var _ = log.Printf
type loopbackRoot struct {
loopbackNode
......@@ -339,3 +337,21 @@ func (n *loopbackNode) ListXAttr(ctx context.Context, dest []byte) (uint32, fuse
sz, err := syscall.Listxattr(n.path(), dest)
return uint32(sz), fuse.ToStatus(err)
}
func (n *loopbackNode) Access(ctx context.Context, mask uint32) fuse.Status {
caller, ok := fuse.FromContext(ctx)
if !ok {
return fuse.EACCES
}
var st syscall.Stat_t
if err := syscall.Stat(n.path(), &st); err != nil {
return fuse.ToStatus(err)
}
if !internal.HasAccess(caller.Uid, caller.Gid, st.Uid, st.Gid, st.Mode, mask) {
return fuse.EACCES
}
return fuse.OK
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment