Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Issue 65: weed-fs 0.51 does not compile under windows

Chris Lu25a3c47defd1
diff --git a/go/stats/disk.go b/go/stats/disk.go
index d0ffcd679f..d5275e5710 100644
--- a/go/stats/disk.go
+++ b/go/stats/disk.go
@@ -1,10 +1,6 @@
-// +build !windows
-
package stats
-import (
- "syscall"
-)
+import ()
type DiskStatus struct {
Dir string
@@ -15,13 +11,6 @@ type DiskStatus struct {
func NewDiskStatus(path string) (disk *DiskStatus) {
disk = &DiskStatus{Dir: path}
- fs := syscall.Statfs_t{}
- err := syscall.Statfs(path, &fs)
- if err != nil {
- return
- }
- disk.All = fs.Blocks * uint64(fs.Bsize)
- disk.Free = fs.Bfree * uint64(fs.Bsize)
- disk.Used = disk.All - disk.Free
+ disk.fillInStatus()
return
}
diff --git a/go/stats/disk_notsupported.go b/go/stats/disk_notsupported.go
new file mode 100644
index 0000000000..1f025ca8ec
--- /dev/null
+++ b/go/stats/disk_notsupported.go
@@ -0,0 +1,9 @@
+// +build windows openbsd netbsd plan9
+
+package stats
+
+import ()
+
+func (disk *DiskStatus) fillInStatus() {
+ return
+}
diff --git a/go/stats/disk_supported.go b/go/stats/disk_supported.go
new file mode 100644
index 0000000000..018628b9b9
--- /dev/null
+++ b/go/stats/disk_supported.go
@@ -0,0 +1,19 @@
+// +build !windows,!openbsd,!netbsd,!plan9
+
+package stats
+
+import (
+ "syscall"
+)
+
+func (disk *DiskStatus) fillInStatus() {
+ fs := syscall.Statfs_t{}
+ err := syscall.Statfs(disk.Dir, &fs)
+ if err != nil {
+ return
+ }
+ disk.All = fs.Blocks * uint64(fs.Bsize)
+ disk.Free = fs.Bfree * uint64(fs.Bsize)
+ disk.Used = disk.All - disk.Free
+ return
+}
diff --git a/go/stats/disk_windows.go b/go/stats/disk_windows.go
deleted file mode 100644
index e3fd7a2ffe..0000000000
--- a/go/stats/disk_windows.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// +build windows
-
-package stats
-
-import (
- "syscall"
-)
-
-type DiskStatus struct {
- Dir string
- All uint64
- Used uint64
- Free uint64
-}
-
-func NewDiskStatus(path string) (disk *DiskStatus) {
- return
-}
diff --git a/go/stats/memory.go b/go/stats/memory.go
index b899e1e4e3..0700d92de2 100644
--- a/go/stats/memory.go
+++ b/go/stats/memory.go
@@ -1,10 +1,7 @@
-// +build !windows
-
package stats
import (
"runtime"
- "syscall"
)
type MemStatus struct {
@@ -26,13 +23,6 @@ func MemStat() MemStatus {
mem.Heap = memStat.HeapAlloc
mem.Stack = memStat.StackInuse
- //system memory usage
- sysInfo := new(syscall.Sysinfo_t)
- err := syscall.Sysinfo(sysInfo)
- if err == nil {
- mem.All = sysInfo.Totalram //* uint64(syscall.Getpagesize())
- mem.Free = sysInfo.Freeram //* uint64(syscall.Getpagesize())
- mem.Used = mem.All - mem.Free
- }
+ mem.fillInStatus()
return mem
}
diff --git a/go/stats/memory_notsupported.go b/go/stats/memory_notsupported.go
new file mode 100644
index 0000000000..64c3d7c2f0
--- /dev/null
+++ b/go/stats/memory_notsupported.go
@@ -0,0 +1,9 @@
+// +build !linux
+
+package stats
+
+import ()
+
+func (mem *MemStatus) fillInStatus() {
+ return
+}
diff --git a/go/stats/memory_supported.go b/go/stats/memory_supported.go
new file mode 100644
index 0000000000..fd0c36d729
--- /dev/null
+++ b/go/stats/memory_supported.go
@@ -0,0 +1,18 @@
+// +build linux
+
+package stats
+
+import (
+ "syscall"
+)
+
+func (mem *MemStatus) fillInStatus() {
+ //system memory usage
+ sysInfo := new(syscall.Sysinfo_t)
+ err := syscall.Sysinfo(sysInfo)
+ if err == nil {
+ mem.All = uint64(sysInfo.Totalram) //* uint64(syscall.Getpagesize())
+ mem.Free = uint64(sysInfo.Freeram) //* uint64(syscall.Getpagesize())
+ mem.Used = mem.All - mem.Free
+ }
+}
diff --git a/go/stats/memory_windows.go b/go/stats/memory_windows.go
deleted file mode 100644
index bb1f9cbbf6..0000000000
--- a/go/stats/memory_windows.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// +build windows
-
-package stats
-
-import (
- "runtime"
-)
-
-type MemStatus struct {
- Goroutines uint32
- All uint32
- Used uint32
- Free uint32
- Self uint64
- Heap uint64
- Stack uint64
-}
-
-func MemStat() MemStatus {
- memStat := new(runtime.MemStats)
- mem.Goroutines = runtime.NumGoroutine()
- runtime.ReadMemStats(memStat)
- mem := MemStatus{}
- mem.Self = memStat.Alloc
- mem.Heap = memStat.HeapAlloc
- mem.Stack = memStat.StackInuse
-
- return mem
-}