Other HelloFS methods.
parent
32d8d19879
commit
5a83972716
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
"github.com/jacobsa/fuse/fuseutil"
|
"github.com/jacobsa/fuse/fuseutil"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A file system with a fixed structure that looks like this:
|
// A file system with a fixed structure that looks like this:
|
||||||
|
@ -137,76 +136,68 @@ func (fs *HelloFS) patchAttributes(
|
||||||
attr.Crtime = now
|
attr.Crtime = now
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) Init(op *fuseops.InitOp) {
|
func (fs *HelloFS) init(op *fuseops.InitOp) {
|
||||||
op.Respond(nil)
|
op.Respond(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) LookUpInode(
|
func (fs *HelloFS) lookUpInode(op *fuseops.LookUpInodeOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.LookUpInodeRequest) (
|
defer func() { op.Respond(err) }()
|
||||||
resp *fuse.LookUpInodeResponse, err error) {
|
|
||||||
resp = &fuse.LookUpInodeResponse{}
|
|
||||||
|
|
||||||
// Find the info for the parent.
|
// Find the info for the parent.
|
||||||
parentInfo, ok := gInodeInfo[req.Parent]
|
parentInfo, ok := gInodeInfo[op.Parent]
|
||||||
if !ok {
|
if !ok {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the child within the parent.
|
// Find the child within the parent.
|
||||||
childInode, err := findChildInode(req.Name, parentInfo.children)
|
childInode, err := findChildInode(op.Name, parentInfo.children)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy over information.
|
// Copy over information.
|
||||||
resp.Entry.Child = childInode
|
op.Entry.Child = childInode
|
||||||
resp.Entry.Attributes = gInodeInfo[childInode].attributes
|
op.Entry.Attributes = gInodeInfo[childInode].attributes
|
||||||
|
|
||||||
// Patch attributes.
|
// Patch attributes.
|
||||||
fs.patchAttributes(&resp.Entry.Attributes)
|
fs.patchAttributes(&op.Entry.Attributes)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) GetInodeAttributes(
|
func (fs *HelloFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.GetInodeAttributesRequest) (
|
defer func() { op.Respond(err) }()
|
||||||
resp *fuse.GetInodeAttributesResponse, err error) {
|
|
||||||
resp = &fuse.GetInodeAttributesResponse{}
|
|
||||||
|
|
||||||
// Find the info for this inode.
|
// Find the info for this inode.
|
||||||
info, ok := gInodeInfo[req.Inode]
|
info, ok := gInodeInfo[op.Inode]
|
||||||
if !ok {
|
if !ok {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy over its attributes.
|
// Copy over its attributes.
|
||||||
resp.Attributes = info.attributes
|
op.Attributes = info.attributes
|
||||||
|
|
||||||
// Patch attributes.
|
// Patch attributes.
|
||||||
fs.patchAttributes(&resp.Attributes)
|
fs.patchAttributes(&op.Attributes)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) OpenDir(
|
func (fs *HelloFS) openDir(op *fuseops.OpenDirOp) {
|
||||||
ctx context.Context,
|
|
||||||
req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) {
|
|
||||||
// Allow opening any directory.
|
// Allow opening any directory.
|
||||||
resp = &fuse.OpenDirResponse{}
|
op.Respond(nil)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) ReadDir(
|
func (fs *HelloFS) readDir(op fuseops.ReadDirOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.ReadDirRequest) (resp *fuse.ReadDirResponse, err error) {
|
defer func() { op.Respond(err) }()
|
||||||
resp = &fuse.ReadDirResponse{}
|
|
||||||
|
|
||||||
// Find the info for this inode.
|
// Find the info for this inode.
|
||||||
info, ok := gInodeInfo[req.Inode]
|
info, ok := gInodeInfo[op.Inode]
|
||||||
if !ok {
|
if !ok {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
|
@ -220,18 +211,18 @@ func (fs *HelloFS) ReadDir(
|
||||||
entries := info.children
|
entries := info.children
|
||||||
|
|
||||||
// Grab the range of interest.
|
// Grab the range of interest.
|
||||||
if req.Offset > fuse.DirOffset(len(entries)) {
|
if op.Offset > fuse.DirOffset(len(entries)) {
|
||||||
err = fuse.EIO
|
err = fuse.EIO
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = entries[req.Offset:]
|
entries = entries[op.Offset:]
|
||||||
|
|
||||||
// Resume at the specified offset into the array.
|
// Resume at the specified offset into the array.
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
resp.Data = fuseutil.AppendDirent(resp.Data, e)
|
op.Data = fuseutil.AppendDirent(op.Data, e)
|
||||||
if len(resp.Data) > req.Size {
|
if len(op.Data) > op.Size {
|
||||||
resp.Data = resp.Data[:req.Size]
|
op.Data = op.Data[:op.Size]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,25 +230,21 @@ func (fs *HelloFS) ReadDir(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) OpenFile(
|
func (fs *HelloFS) openFile(op *fuseops.OpenFileOp) {
|
||||||
ctx context.Context,
|
|
||||||
req *fuse.OpenFileRequest) (resp *fuse.OpenFileResponse, err error) {
|
|
||||||
// Allow opening any file.
|
// Allow opening any file.
|
||||||
resp = &fuse.OpenFileResponse{}
|
op.Respond(nil)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *HelloFS) ReadFile(
|
func (fs *HelloFS) readFile(op *fuseops.ReadFileOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.ReadFileRequest) (resp *fuse.ReadFileResponse, err error) {
|
defer func() { op.Respond(err) }()
|
||||||
resp = &fuse.ReadFileResponse{}
|
|
||||||
|
|
||||||
// Let io.ReaderAt deal with the semantics.
|
// Let io.ReaderAt deal with the semantics.
|
||||||
reader := strings.NewReader("Hello, world!")
|
reader := strings.NewReader("Hello, world!")
|
||||||
|
|
||||||
resp.Data = make([]byte, req.Size)
|
op.Data = make([]byte, op.Size)
|
||||||
n, err := reader.ReadAt(resp.Data, req.Offset)
|
n, err := reader.ReadAt(op.Data, op.Offset)
|
||||||
resp.Data = resp.Data[:n]
|
op.Data = op.Data[:n]
|
||||||
|
|
||||||
// Special case: FUSE doesn't expect us to return io.EOF.
|
// Special case: FUSE doesn't expect us to return io.EOF.
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
|
Loading…
Reference in New Issue