add template for fs.FSStatfser

This commit is contained in:
Chris Lu 2018-11-22 23:05:22 -08:00
parent 6344469a9b
commit 2e32b44061

View file

@ -1,7 +1,9 @@
package filesys package filesys
import ( import (
"context"
"fmt" "fmt"
"math"
"sync" "sync"
"time" "time"
@ -26,6 +28,9 @@ type Option struct {
EntryCacheTtl time.Duration EntryCacheTtl time.Duration
} }
var _ = fs.FS(&WFS{})
var _ = fs.FSStatfser(&WFS{})
type WFS struct { type WFS struct {
option *Option option *Option
listDirectoryEntriesCache *ccache.Cache listDirectoryEntriesCache *ccache.Cache
@ -128,3 +133,34 @@ func (wfs *WFS) ReleaseHandle(fullpath string, handleId fuse.HandleID) {
return return
} }
// Statfs is called to obtain file system metadata. Implements fuse.FSStatfser
func (wfs *WFS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.StatfsResponse) error {
glog.V(4).Infof("reading fs stats: %+v", req)
totalDiskSize := uint64(0)
usedDiskSize := uint64(0)
actualFileCount := uint64(0)
// Compute the total number of available blocks
resp.Blocks = totalDiskSize / blockSize
// Compute the number of used blocks
numblocks := uint64(usedDiskSize / blockSize)
// Report the number of free and available blocks for the block size
resp.Bfree = resp.Blocks - numblocks
resp.Bavail = resp.Blocks - numblocks
resp.Bsize = uint32(blockSize)
// Report the total number of possible files in the file system (and those free)
resp.Files = math.MaxInt64
resp.Ffree = math.MaxInt64 - actualFileCount
// Report the maximum length of a name and the minimum fragment size
resp.Namelen = 1024
resp.Frsize = uint32(blockSize)
return nil
}