Commit f5e4c658 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: add MemRegularFile.Flush

parent 9723c2be
...@@ -728,6 +728,7 @@ func (b *rawBridge) Flush(cancel <-chan struct{}, input *fuse.FlushIn) fuse.Stat ...@@ -728,6 +728,7 @@ func (b *rawBridge) Flush(cancel <-chan struct{}, input *fuse.FlushIn) fuse.Stat
if fl, ok := f.file.(FileFlusher); ok { if fl, ok := f.file.(FileFlusher); ok {
return errnoToStatus(fl.Flush(&fuse.Context{Caller: input.Caller, Cancel: cancel})) return errnoToStatus(fl.Flush(&fuse.Context{Caller: input.Caller, Cancel: cancel}))
} }
// XXX should return OK to reflect r/o filesystem?
return fuse.ENOTSUP return fuse.ENOTSUP
} }
......
...@@ -22,6 +22,7 @@ type MemRegularFile struct { ...@@ -22,6 +22,7 @@ type MemRegularFile struct {
var _ = (Opener)((*MemRegularFile)(nil)) var _ = (Opener)((*MemRegularFile)(nil))
var _ = (Getattrer)((*MemRegularFile)(nil)) var _ = (Getattrer)((*MemRegularFile)(nil))
var _ = (Reader)((*MemRegularFile)(nil)) var _ = (Reader)((*MemRegularFile)(nil))
var _ = (Flusher)((*MemRegularFile)(nil))
func (f *MemRegularFile) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, errno syscall.Errno) { func (f *MemRegularFile) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, errno syscall.Errno) {
if flags&(syscall.O_RDWR) != 0 || flags&syscall.O_WRONLY != 0 { if flags&(syscall.O_RDWR) != 0 || flags&syscall.O_WRONLY != 0 {
...@@ -38,6 +39,10 @@ func (f *MemRegularFile) Getattr(ctx context.Context, fh FileHandle, out *fuse.A ...@@ -38,6 +39,10 @@ func (f *MemRegularFile) Getattr(ctx context.Context, fh FileHandle, out *fuse.A
return OK return OK
} }
func (f *MemRegularFile) Flush(ctx context.Context, fh FileHandle) syscall.Errno {
return 0
}
func (f *MemRegularFile) Read(ctx context.Context, fh FileHandle, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { func (f *MemRegularFile) Read(ctx context.Context, fh FileHandle, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
end := int(off) + len(dest) end := int(off) + len(dest)
if end > len(f.Data) { if end > len(f.Data) {
......
...@@ -6,7 +6,6 @@ package nodefs ...@@ -6,7 +6,6 @@ package nodefs
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"syscall" "syscall"
"testing" "testing"
...@@ -54,11 +53,23 @@ func TestDataFile(t *testing.T) { ...@@ -54,11 +53,23 @@ func TestDataFile(t *testing.T) {
}) })
defer clean() defer clean()
c, err := ioutil.ReadFile(mntDir + "/file") fd, err := syscall.Open(mntDir+"/file", syscall.O_RDONLY, 0)
if err != nil { if err != nil {
t.Fatalf("ReadFile: %v", err) t.Fatalf("Open: %v", err)
} }
if got := string(c); got != want {
var buf [1024]byte
n, err := syscall.Read(fd, buf[:])
if err != nil {
t.Errorf("Read: %v", err)
}
if err := syscall.Close(fd); err != nil {
t.Errorf("Close: %v", err)
}
got := string(buf[:n])
if got != want {
t.Errorf("got %q want %q", got, want) t.Errorf("got %q want %q", got, want)
} }
} }
......
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