Commit 55f8d0c5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: fsyncdir, statfs.

parent 6a644588
......@@ -100,6 +100,8 @@ type Operations interface {
inode() *Inode
setInode(*Inode) bool
StatFs(ctx context.Context, out *fuse.StatfsOut) 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)
......
......@@ -638,11 +638,13 @@ func (b *rawBridge) ReadDirPlus(input *fuse.ReadIn, out *fuse.DirEntryList) fuse
}
func (b *rawBridge) FsyncDir(input *fuse.FsyncIn) (status fuse.Status) {
return
n, _ := b.inode(input.NodeId, input.Fh)
return n.node.Fsync(context.TODO(), nil, input.FsyncFlags)
}
func (b *rawBridge) StatFs(input *fuse.InHeader, out *fuse.StatfsOut) (status fuse.Status) {
return
n, _ := b.inode(input.NodeId, 0)
return n.node.StatFs(context.TODO(), out)
}
func (b *rawBridge) Init(s *fuse.Server) {
......
......@@ -47,6 +47,12 @@ func (dn *DefaultOperations) setInode(inode *Inode) bool {
nil, unsafe.Pointer(inode))
}
func (dn *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status {
// this should be defined on OSX, or the FS won't mount
*out = fuse.StatfsOut{}
return fuse.OK
}
func (dn *DefaultOperations) inode() *Inode {
return (*Inode)(atomic.LoadPointer(
(*unsafe.Pointer)(unsafe.Pointer(&dn.inode_))))
......@@ -59,6 +65,7 @@ func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.E
func (n *DefaultOperations) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status) {
return nil, fuse.ENOSYS
}
func (n *DefaultOperations) Mknod(ctx context.Context, name string, mode uint32, dev uint32, out *fuse.EntryOut) (*Inode, fuse.Status) {
return nil, fuse.ENOSYS
}
......
......@@ -30,6 +30,16 @@ func (n *loopbackRoot) newLoopbackNode() *loopbackNode {
}
}
func (n *loopbackNode) StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status {
s := syscall.Statfs_t{}
err := syscall.Statfs(n.path(), &s)
if err != nil {
return fuse.ToStatus(err)
}
out.FromStatfsT(&s)
return fuse.OK
}
func (n *loopbackRoot) GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
var err error = nil
st := syscall.Stat_t{}
......
......@@ -537,3 +537,29 @@ func TestReadDir(t *testing.T) {
}
}
}
// This test is racy. If an external process consumes space while this
// runs, we may see spurious differences between the two statfs() calls.
func TestStatFs(t *testing.T) {
tc := newTestCase(t)
defer tc.Clean()
empty := syscall.Statfs_t{}
orig := empty
if err := syscall.Statfs(tc.origDir, &orig); err != nil {
t.Fatal("statfs orig", err)
}
mnt := syscall.Statfs_t{}
if err := syscall.Statfs(tc.mntDir, &mnt); err != nil {
t.Fatal("statfs mnt", err)
}
var mntFuse, origFuse fuse.StatfsOut
mntFuse.FromStatfsT(&mnt)
origFuse.FromStatfsT(&orig)
if !reflect.DeepEqual(mntFuse, origFuse) {
t.Errorf("Got %#v, want %#v", mntFuse, origFuse)
}
}
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