From a2c55f32d0725328128bf99f73d32870a0723a2a Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 2 Mar 2015 15:18:23 +1100 Subject: [PATCH] Implemented much of memFS.LookUpInode. --- samples/memfs/dir.go | 5 +++++ samples/memfs/fs.go | 41 +++++++++++++++++++++++++++++++++++++++++ samples/memfs/inode.go | 4 ++++ 3 files changed, 50 insertions(+) diff --git a/samples/memfs/dir.go b/samples/memfs/dir.go index a2cc7fb..9f127b1 100644 --- a/samples/memfs/dir.go +++ b/samples/memfs/dir.go @@ -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) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 406828f..055fdf1 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -5,6 +5,7 @@ package memfs import ( "fmt" + "time" "github.com/jacobsa/fuse" "github.com/jacobsa/fuse/fuseutil" @@ -113,6 +114,17 @@ func (fs *memFS) Init( 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. // // LOCKS_EXCLUDED(fs.mu) @@ -130,6 +142,35 @@ func (fs *memFS) getDirOrDie(inodeID fuse.InodeID) (d *memDir) { 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( ctx context.Context, req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) { diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index d3ae224..81226db 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -6,6 +6,8 @@ package memfs import ( "fmt" "reflect" + + "github.com/jacobsa/fuse" ) // 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))) } } + +func (inode *inode) Attributes() fuse.InodeAttributes