Enable StatFS on dynamicfs

MacOS apparently invokes StatFS on os.Lstat/os.Stat. Note that the
return fields are not actually populated here.
geesefs-0-30-9
Ben Sidhom 2017-05-08 14:27:10 -07:00 committed by Aaron Jacobs
parent 8edb6e4462
commit 6a1014cd27
1 changed files with 40 additions and 36 deletions

View File

@ -1,20 +1,20 @@
package dynamicfs package dynamicfs
import ( import (
"strings" "fmt"
"io" "io"
"log"
"os"
"strings"
"sync"
"time"
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/jacobsa/timeutil"
"github.com/jacobsa/fuse" "github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/fuseops" "github.com/jacobsa/fuse/fuseops"
"os" "github.com/jacobsa/fuse/fuseutil"
"fmt" "github.com/jacobsa/timeutil"
"log"
"sync"
"time"
) )
// Create a file system that contains 2 files (`age` and `weekday`) and no directories. Every time // Create a file system that contains 2 files (`age` and `weekday`) and no directories. Every time
@ -34,8 +34,8 @@ import (
func NewDynamicFS(clock timeutil.Clock) (server fuse.Server, err error) { func NewDynamicFS(clock timeutil.Clock) (server fuse.Server, err error) {
createTime := clock.Now() createTime := clock.Now()
fs := &dynamicFS{ fs := &dynamicFS{
clock: clock, clock: clock,
createTime: createTime, createTime: createTime,
fileHandles: make(map[fuseops.HandleID]string), fileHandles: make(map[fuseops.HandleID]string),
} }
server = fuseutil.NewFileSystemServer(fs) server = fuseutil.NewFileSystemServer(fs)
@ -44,10 +44,10 @@ func NewDynamicFS(clock timeutil.Clock) (server fuse.Server, err error) {
type dynamicFS struct { type dynamicFS struct {
fuseutil.NotImplementedFileSystem fuseutil.NotImplementedFileSystem
mu sync.Mutex mu sync.Mutex
clock timeutil.Clock clock timeutil.Clock
createTime time.Time createTime time.Time
nextHandle fuseops.HandleID nextHandle fuseops.HandleID
fileHandles map[fuseops.HandleID]string fileHandles map[fuseops.HandleID]string
} }
@ -79,9 +79,9 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{
children: []fuseutil.Dirent{ children: []fuseutil.Dirent{
{ {
Offset: 1, Offset: 1,
Inode: ageInode, Inode: ageInode,
Name: "age", Name: "age",
Type: fuseutil.DT_File, Type: fuseutil.DT_File,
}, },
{ {
Offset: 2, Offset: 2,
@ -96,7 +96,7 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{
ageInode: { ageInode: {
attributes: fuseops.InodeAttributes{ attributes: fuseops.InodeAttributes{
Nlink: 1, Nlink: 1,
Mode: 0444, Mode: 0444,
}, },
}, },
@ -104,15 +104,15 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{
weekdayInode: { weekdayInode: {
attributes: fuseops.InodeAttributes{ attributes: fuseops.InodeAttributes{
Nlink: 1, Nlink: 1,
Mode: 0444, Mode: 0444,
// Size left at 0. // Size left at 0.
}, },
}, },
} }
func findChildInode( func findChildInode(
name string, name string,
children []fuseutil.Dirent) (inode fuseops.InodeID, err error) { children []fuseutil.Dirent) (inode fuseops.InodeID, err error) {
for _, e := range children { for _, e := range children {
if e.Name == name { if e.Name == name {
inode = e.Inode inode = e.Inode
@ -131,13 +131,12 @@ func (fs *dynamicFS) findUnusedHandle() fuseops.HandleID {
handle++ handle++
} }
fs.nextHandle = handle + 1 fs.nextHandle = handle + 1
log.Printf("Minting new handle: %d", handle)
return handle return handle
} }
func (fs *dynamicFS) GetInodeAttributes( func (fs *dynamicFS) GetInodeAttributes(
ctx context.Context, ctx context.Context,
op *fuseops.GetInodeAttributesOp) (err error) { op *fuseops.GetInodeAttributesOp) (err error) {
// Find the info for this inode. // Find the info for this inode.
info, ok := gInodeInfo[op.Inode] info, ok := gInodeInfo[op.Inode]
if !ok { if !ok {
@ -150,8 +149,8 @@ op *fuseops.GetInodeAttributesOp) (err error) {
} }
func (fs *dynamicFS) LookUpInode( func (fs *dynamicFS) LookUpInode(
ctx context.Context, ctx context.Context,
op *fuseops.LookUpInodeOp) (err error) { op *fuseops.LookUpInodeOp) (err error) {
// Find the info for the parent. // Find the info for the parent.
parentInfo, ok := gInodeInfo[op.Parent] parentInfo, ok := gInodeInfo[op.Parent]
if !ok { if !ok {
@ -173,15 +172,15 @@ op *fuseops.LookUpInodeOp) (err error) {
} }
func (fs *dynamicFS) OpenDir( func (fs *dynamicFS) OpenDir(
ctx context.Context, ctx context.Context,
op *fuseops.OpenDirOp) (err error) { op *fuseops.OpenDirOp) (err error) {
// Allow opening directory. // Allow opening directory.
return return
} }
func (fs *dynamicFS) ReadDir( func (fs *dynamicFS) ReadDir(
ctx context.Context, ctx context.Context,
op *fuseops.ReadDirOp) (err error) { op *fuseops.ReadDirOp) (err error) {
// Find the info for this inode. // Find the info for this inode.
info, ok := gInodeInfo[op.Inode] info, ok := gInodeInfo[op.Inode]
if !ok { if !ok {
@ -218,8 +217,8 @@ op *fuseops.ReadDirOp) (err error) {
} }
func (fs *dynamicFS) OpenFile( func (fs *dynamicFS) OpenFile(
ctx context.Context, ctx context.Context,
op *fuseops.OpenFileOp) (err error) { op *fuseops.OpenFileOp) (err error) {
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
var contents string var contents string
@ -243,8 +242,8 @@ op *fuseops.OpenFileOp) (err error) {
} }
func (fs *dynamicFS) ReadFile( func (fs *dynamicFS) ReadFile(
ctx context.Context, ctx context.Context,
op *fuseops.ReadFileOp) (err error) { op *fuseops.ReadFileOp) (err error) {
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
contents, ok := fs.fileHandles[op.Handle] contents, ok := fs.fileHandles[op.Handle]
@ -262,8 +261,8 @@ op *fuseops.ReadFileOp) (err error) {
} }
func (fs *dynamicFS) ReleaseFileHandle( func (fs *dynamicFS) ReleaseFileHandle(
ctx context.Context, ctx context.Context,
op *fuseops.ReleaseFileHandleOp) (err error) { op *fuseops.ReleaseFileHandleOp) (err error) {
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
_, ok := fs.fileHandles[op.Handle] _, ok := fs.fileHandles[op.Handle]
@ -275,3 +274,8 @@ func (fs *dynamicFS) ReleaseFileHandle(
delete(fs.fileHandles, op.Handle) delete(fs.fileHandles, op.Handle)
return return
} }
func (fs *dynamicFS) StatFS(ctx context.Context,
op *fuseops.StatFSOp) (err error) {
return
}