Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

mount,cmount: clip the number of blocks to 2^32-1 on macOS

Nick Craig-Wood174ca2293668
diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go
index 83e0f819c..b0a5e511e 100644
--- a/cmd/cmount/fs.go
+++ b/cmd/cmount/fs.go
@@ -8,11 +8,11 @@ import (
"io"
"os"
"path"
- "runtime"
"sync"
"time"
"github.com/billziss-gh/cgofuse/fuse"
+ "github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/log"
"github.com/ncw/rclone/vfs"
@@ -263,10 +263,7 @@ func (fsys *FS) Releasedir(path string, fh uint64) (errc int) {
func (fsys *FS) Statfs(path string, stat *fuse.Statfs_t) (errc int) {
defer log.Trace(path, "")("stat=%+v, errc=%d", stat, &errc)
const blockSize = 4096
- fsBlocks := uint64(1 << 50)
- if runtime.GOOS == "windows" {
- fsBlocks = (1 << 43) - 1
- }
+ const fsBlocks = (1 << 50) / blockSize
stat.Blocks = fsBlocks // Total data blocks in file system.
stat.Bfree = fsBlocks // Free blocks in file system.
stat.Bavail = fsBlocks // Free blocks in file system if you're not root.
@@ -285,6 +282,9 @@ func (fsys *FS) Statfs(path string, stat *fuse.Statfs_t) (errc int) {
if free >= 0 {
stat.Bavail = uint64(free) / blockSize
}
+ mountlib.ClipBlocks(&stat.Blocks)
+ mountlib.ClipBlocks(&stat.Bfree)
+ mountlib.ClipBlocks(&stat.Bavail)
return 0
}
diff --git a/cmd/mount/fs.go b/cmd/mount/fs.go
index caab6a060..68e7cc5b0 100644
--- a/cmd/mount/fs.go
+++ b/cmd/mount/fs.go
@@ -9,6 +9,7 @@ import (
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
+ "github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/log"
"github.com/ncw/rclone/vfs"
@@ -72,6 +73,9 @@ func (f *FS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.Sta
if free >= 0 {
resp.Bavail = uint64(free) / blockSize
}
+ mountlib.ClipBlocks(&resp.Blocks)
+ mountlib.ClipBlocks(&resp.Bfree)
+ mountlib.ClipBlocks(&resp.Bavail)
return nil
}
diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go
index e9f6e7456..f3fe2ae4f 100644
--- a/cmd/mountlib/mount.go
+++ b/cmd/mountlib/mount.go
@@ -293,3 +293,22 @@ be copied to the vfs cache before opening with --vfs-cache-mode full.
return commandDefintion
}
+
+// ClipBlocks clips the blocks pointed to to the OS max
+func ClipBlocks(b *uint64) {
+ var max uint64
+ switch runtime.GOOS {
+ case "windows":
+ max = (1 << 43) - 1
+ case "darwin":
+ // OSX FUSE only supports 32 bit number of blocks
+ // https://github.com/osxfuse/osxfuse/issues/396
+ max = (1 << 32) - 1
+ default:
+ // no clipping
+ return
+ }
+ if *b > max {
+ *b = max
+ }
+}