func (benchFS) Init(ctx context.Context, req *fuse.InitRequest, resp *fuse.InitResponse) error {
	resp.MaxReadahead = 64 * 1024 * 1024
	resp.Flags |= fuse.InitAsyncRead
	return nil
}

func (f benchFS) Root() (fs.Node, error) {
	return benchDir{conf: f.conf}, nil
}

type benchDir struct {
	conf *benchConfig
}

var _ = fs.Node(benchDir{})
var _ = fs.NodeStringLookuper(benchDir{})
var _ = fs.Handle(benchDir{})
var _ = fs.HandleReadDirAller(benchDir{})

func (benchDir) Attr(ctx context.Context, a *fuse.Attr) error {
	a.Inode = 1
	a.Mode = os.ModeDir | 0555
	return nil
}

func (d benchDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
	if name == "bench" {
		return benchFile{conf: d.conf}, nil
	}
	return nil, fuse.ENOENT
}
Exemple #2
0
	a.Mode = 0666
	return nil
}

// Dir can be embedded in a struct to make it look like a directory.
type Dir struct{}

func (f Dir) Attr(ctx context.Context, a *fuse.Attr) error {
	a.Mode = os.ModeDir | 0777
	return nil
}

// ChildMap is a directory with child nodes looked up from a map.
type ChildMap map[string]fs.Node

var _ = fs.Node(ChildMap{})
var _ = fs.NodeStringLookuper(ChildMap{})

func (f ChildMap) Attr(ctx context.Context, a *fuse.Attr) error {
	a.Mode = os.ModeDir | 0777
	return nil
}

func (f ChildMap) Lookup(ctx context.Context, name string) (fs.Node, error) {
	child, ok := f[name]
	if !ok {
		return nil, fuse.ENOENT
	}
	return child, nil
}