Implemented much of memFS.LookUpInode.
parent
d8355cb155
commit
a2c55f32d0
|
@ -46,3 +46,8 @@ func (d *memDir) checkInvariants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the inode ID of the child with the given name.
|
||||||
|
//
|
||||||
|
// LOCKS_EXCLUDED(d.mu)
|
||||||
|
func (d *memDir) LookUpInode(name string) (id fuse.InodeID, ok bool)
|
||||||
|
|
|
@ -5,6 +5,7 @@ package memfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
"github.com/jacobsa/fuse/fuseutil"
|
"github.com/jacobsa/fuse/fuseutil"
|
||||||
|
@ -113,6 +114,17 @@ func (fs *memFS) Init(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Panic if out of range.
|
||||||
|
//
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *memFS) getInodeOrDie(inodeID fuse.InodeID) (inode *inode) {
|
||||||
|
fs.mu.RLock()
|
||||||
|
defer fs.mu.RUnlock()
|
||||||
|
|
||||||
|
inode = &fs.inodes[inodeID]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Panic if not a live dir.
|
// Panic if not a live dir.
|
||||||
//
|
//
|
||||||
// LOCKS_EXCLUDED(fs.mu)
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
@ -130,6 +142,35 @@ func (fs *memFS) getDirOrDie(inodeID fuse.InodeID) (d *memDir) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *memFS) LookUpInode(
|
||||||
|
ctx context.Context,
|
||||||
|
req *fuse.LookUpInodeRequest) (resp *fuse.LookUpInodeResponse, err error) {
|
||||||
|
resp = &fuse.LookUpInodeResponse{}
|
||||||
|
|
||||||
|
// Grab the parent directory.
|
||||||
|
d := fs.getDirOrDie(req.Parent)
|
||||||
|
|
||||||
|
// Does the directory have an entry with the given name?
|
||||||
|
childID, ok := d.LookUpInode(req.Name)
|
||||||
|
if !ok {
|
||||||
|
err = fuse.ENOENT
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up the child.
|
||||||
|
child := fs.getInodeOrDie(childID)
|
||||||
|
|
||||||
|
// Fill in the response.
|
||||||
|
resp.Attributes = child.Attributes()
|
||||||
|
|
||||||
|
// We don't spontaneously mutate, so the kernel can cache as long as it wants
|
||||||
|
// (since it also handles invalidation).
|
||||||
|
resp.AttributesExpiration = fs.clock.Now().Add(365 * 24 * time.Hour)
|
||||||
|
resp.EntryExpiration = resp.EntryExpiration
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (fs *memFS) OpenDir(
|
func (fs *memFS) OpenDir(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) {
|
req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) {
|
||||||
|
|
|
@ -6,6 +6,8 @@ package memfs
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jacobsa/fuse"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common attributes for files and directories.
|
// Common attributes for files and directories.
|
||||||
|
@ -31,3 +33,5 @@ func (inode *inode) checkInvariants() {
|
||||||
fmt.Sprintf("Unexpected inode impl type: %v", reflect.TypeOf(inode.impl)))
|
fmt.Sprintf("Unexpected inode impl type: %v", reflect.TypeOf(inode.impl)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (inode *inode) Attributes() fuse.InodeAttributes
|
||||||
|
|
Loading…
Reference in New Issue