mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add template for fs.FSStatfser
This commit is contained in:
parent
6344469a9b
commit
2e32b44061
|
@ -1,7 +1,9 @@
|
|||
package filesys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -26,6 +28,9 @@ type Option struct {
|
|||
EntryCacheTtl time.Duration
|
||||
}
|
||||
|
||||
var _ = fs.FS(&WFS{})
|
||||
var _ = fs.FSStatfser(&WFS{})
|
||||
|
||||
type WFS struct {
|
||||
option *Option
|
||||
listDirectoryEntriesCache *ccache.Cache
|
||||
|
@ -128,3 +133,34 @@ func (wfs *WFS) ReleaseHandle(fullpath string, handleId fuse.HandleID) {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue