diff --git a/disk/disk.go b/disk/disk.go index 38d8a8f1..fb2eaf18 100644 --- a/disk/disk.go +++ b/disk/disk.go @@ -1,6 +1,7 @@ package disk import ( + "context" "encoding/json" "github.com/shirou/gopsutil/internal/common" @@ -59,3 +60,23 @@ func (d IOCountersStat) String() string { s, _ := json.Marshal(d) return string(s) } + +// Usage returns a file system usage. path is a filesystem path such +// as "/", not device file path like "/dev/vda1". If you want to use +// a return value of disk.Partitions, use "Mountpoint" not "Device". +func Usage(path string) (*UsageStat, error) { + return UsageWithContext(context.Background(), path) +} + +// Partitions returns disk partitions. If all is false, returns +// physical devices only (e.g. hard disks, cd-rom drives, USB keys) +// and ignore all others (e.g. memory partitions such as /dev/shm) +// +// 'all' argument is ignored for BSD, see: https://github.com/giampaolo/psutil/issues/906 +func Partitions(all bool) ([]PartitionStat, error) { + return PartitionsWithContext(context.Background(), all) +} + +func IOCounters(names ...string) (map[string]IOCountersStat, error) { + return IOCountersWithContext(context.Background(), names...) +} diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index b0fc29a9..b23e7d04 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -9,10 +9,6 @@ import ( "golang.org/x/sys/unix" ) -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - // PartitionsWithContext returns disk partition. // 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { diff --git a/disk/disk_darwin_cgo.go b/disk/disk_darwin_cgo.go index 8a1848ed..d3db753b 100644 --- a/disk/disk_darwin_cgo.go +++ b/disk/disk_darwin_cgo.go @@ -17,10 +17,6 @@ import ( "github.com/shirou/gopsutil/internal/common" ) -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { var buf [C.NDRIVE]C.DriveStats n, err := C.readdrivestat(&buf[0], C.int(len(buf))) diff --git a/disk/disk_darwin_nocgo.go b/disk/disk_darwin_nocgo.go index fe76d83e..4fb8aca4 100644 --- a/disk/disk_darwin_nocgo.go +++ b/disk/disk_darwin_nocgo.go @@ -9,10 +9,6 @@ import ( "github.com/shirou/gopsutil/internal/common" ) -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { return nil, common.ErrNotImplementedError } diff --git a/disk/disk_fallback.go b/disk/disk_fallback.go index 22eb5079..dd446ff8 100644 --- a/disk/disk_fallback.go +++ b/disk/disk_fallback.go @@ -8,26 +8,14 @@ import ( "github.com/shirou/gopsutil/internal/common" ) -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { return nil, common.ErrNotImplementedError } -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { return []PartitionStat{}, common.ErrNotImplementedError } -func Usage(path string) (*UsageStat, error) { - return UsageWithContext(context.Background(), path) -} - func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { return nil, common.ErrNotImplementedError } diff --git a/disk/disk_freebsd.go b/disk/disk_freebsd.go index 9882781a..81245002 100644 --- a/disk/disk_freebsd.go +++ b/disk/disk_freebsd.go @@ -13,10 +13,6 @@ import ( "github.com/shirou/gopsutil/internal/common" ) -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - // PartitionsWithContext returns disk partition. // 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { @@ -97,10 +93,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, nil } -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { // statinfo->devinfo->devstat // /usr/include/devinfo.h diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 9fa311dc..887c79a3 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -218,13 +218,6 @@ var fsTypeMap = map[int64]string{ ZFS_SUPER_MAGIC: "zfs", /* 0x2FC12FC1 local */ } -// Partitions returns disk partitions. If all is false, returns -// physical devices only (e.g. hard disks, cd-rom drives, USB keys) -// and ignore all others (e.g. memory partitions such as /dev/shm) -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { useMounts := false @@ -354,10 +347,6 @@ func getFileSystems() ([]string, error) { return ret, nil } -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { filename := common.HostProc("diskstats") lines, err := common.ReadLines(filename) diff --git a/disk/disk_openbsd.go b/disk/disk_openbsd.go index 741aa89b..e6755803 100644 --- a/disk/disk_openbsd.go +++ b/disk/disk_openbsd.go @@ -11,12 +11,6 @@ import ( "golang.org/x/sys/unix" ) -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - -// PartitionsWithContext returns disk partition. -// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat @@ -74,10 +68,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, nil } -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { ret := make(map[string]IOCountersStat) @@ -130,10 +120,6 @@ func parseDiskstats(buf []byte) (Diskstats, error) { return ds, nil } -func Usage(path string) (*UsageStat, error) { - return UsageWithContext(context.Background(), path) -} - func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := unix.Statfs_t{} err := unix.Statfs(path, &stat) diff --git a/disk/disk_solaris.go b/disk/disk_solaris.go index c6608357..1c440ac4 100644 --- a/disk/disk_solaris.go +++ b/disk/disk_solaris.go @@ -38,10 +38,6 @@ var ( } ) -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS) @@ -83,18 +79,10 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, err } -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { return nil, common.ErrNotImplementedError } -func Usage(path string) (*UsageStat, error) { - return UsageWithContext(context.Background(), path) -} - func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { statvfs := unix.Statvfs_t{} if err := unix.Statvfs(path, &statvfs); err != nil { diff --git a/disk/disk_unix.go b/disk/disk_unix.go index 86ab99cb..9ca3bb34 100644 --- a/disk/disk_unix.go +++ b/disk/disk_unix.go @@ -9,13 +9,6 @@ import ( "golang.org/x/sys/unix" ) -// Usage returns a file system usage. path is a filesystem path such -// as "/", not device file path like "/dev/vda1". If you want to use -// a return value of disk.Partitions, use "Mountpoint" not "Device". -func Usage(path string) (*UsageStat, error) { - return UsageWithContext(context.Background(), path) -} - func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := unix.Statfs_t{} err := unix.Statfs(path, &stat) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index a77a15b7..03dccb21 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -43,10 +43,6 @@ type diskPerformance struct { alignmentPadding uint32 // necessary for 32bit support, see https://github.com/elastic/beats/pull/16553 } -func Usage(path string) (*UsageStat, error) { - return UsageWithContext(context.Background(), path) -} - func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { lpFreeBytesAvailable := int64(0) lpTotalNumberOfBytes := int64(0) @@ -73,10 +69,6 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { return ret, nil } -func Partitions(all bool) ([]PartitionStat, error) { - return PartitionsWithContext(context.Background(), all) -} - func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat lpBuffer := make([]byte, 254) @@ -139,10 +131,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, nil } -func IOCounters(names ...string) (map[string]IOCountersStat, error) { - return IOCountersWithContext(context.Background(), names...) -} - func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { // https://github.com/giampaolo/psutil/blob/544e9daa4f66a9f80d7bf6c7886d693ee42f0a13/psutil/arch/windows/disk.c#L83 drivemap := make(map[string]IOCountersStat, 0)