Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fs: per-storage StatFs data.

  • Loading branch information...
commit 731851c9363ffa26206219b9fbec1897f0b3d9d1 1 parent 3383d4f
@hanwen authored
Showing with 40 additions and 31 deletions.
  1. +40 −31 fs/fs.go
View
71 fs/fs.go
@@ -91,29 +91,6 @@ func (fs *DeviceFs) String() string {
// TODO - this should be per storage and return just the free space in
// the storage.
-func (fs *DeviceFs) statFs() *fuse.StatfsOut {
- total := uint64(0)
- free := uint64(0)
- for _, sid := range fs.storages {
- var info mtp.StorageInfo
- if err := fs.dev.GetStorageInfo(sid, &info); err != nil {
- log.Printf("GetStorageInfo %x: %v", sid, err)
- continue
- }
-
- total += uint64(info.MaxCapability)
- free += uint64(info.FreeSpaceInBytes)
- }
-
- bs := uint64(1024)
-
- return &fuse.StatfsOut{
- Bsize: uint32(bs),
- Blocks: total / bs,
- Bavail: free / bs,
- Bfree: free / bs,
- }
-}
func (fs *DeviceFs) newFile(obj mtp.ObjectInfo, size int64, id uint32) (node fuse.FsNode) {
if obj.CompressedSize != 0xFFFFFFFF {
@@ -143,10 +120,6 @@ type rootNode struct {
fs *DeviceFs
}
-func (n *rootNode) StatFs() *fuse.StatfsOut {
- return n.fs.statFs()
-}
-
const NOPARENT_ID = 0xFFFFFFFF
func (fs *DeviceFs) OnMount(conn *fuse.FileSystemConnector) {
@@ -168,6 +141,24 @@ func (fs *DeviceFs) OnMount(conn *fuse.FileSystemConnector) {
}
}
+func (n *rootNode) StatFs() *fuse.StatfsOut {
+ total := uint64(0)
+ free := uint64(0)
+ for _, ch := range n.Inode().Children() {
+ if s := ch.FsNode().StatFs(); s != nil {
+ total += s.Blocks
+ free += s.Bfree
+ }
+ }
+
+ return &fuse.StatfsOut{
+ Bsize: uint32(1024),
+ Blocks: total,
+ Bavail: free,
+ Bfree: free,
+ }
+}
+
const forbidden = ":*?\"<>|"
func SanitizeDosName(name string) string {
@@ -210,6 +201,28 @@ type mtpNodeImpl struct {
Size int64
}
+func (n *mtpNodeImpl) StatFs() *fuse.StatfsOut {
+ total := uint64(0)
+ free := uint64(0)
+
+ var info mtp.StorageInfo
+ if err := n.fs.dev.GetStorageInfo(n.StorageID(), &info); err != nil {
+ log.Printf("GetStorageInfo %x: %v", n.StorageID(), err)
+ return nil
+ }
+
+ total += uint64(info.MaxCapability)
+ free += uint64(info.FreeSpaceInBytes)
+ bs := uint64(1024)
+
+ return &fuse.StatfsOut{
+ Bsize: uint32(bs),
+ Blocks: total / bs,
+ Bavail: free / bs,
+ Bfree: free / bs,
+ }
+}
+
func (n *mtpNodeImpl) GetAttr(out *fuse.Attr, file fuse.File, context *fuse.Context) (code fuse.Status) {
out.Mode = fuse.S_IFREG | 0644
f := n.obj
@@ -250,10 +263,6 @@ func (n *mtpNodeImpl) SetName(nm string) {
n.obj.Filename = nm
}
-func (n *mtpNodeImpl) StatFs() *fuse.StatfsOut {
- return n.fs.statFs()
-}
-
func (n *mtpNodeImpl) StorageID() uint32 {
return n.obj.StorageID
}
Please sign in to comment.
Something went wrong with that request. Please try again.