2024-02-17 03:48:29 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-12-22 21:54:41 +00:00
|
|
|
//go:build darwin
|
2014-08-08 23:09:28 +09:00
|
|
|
|
2014-12-30 22:09:05 +09:00
|
|
|
package disk
|
2014-08-08 23:09:28 +09:00
|
|
|
|
2014-11-27 10:18:15 +09:00
|
|
|
import (
|
2017-12-31 15:25:49 +09:00
|
|
|
"context"
|
2014-12-28 22:30:07 +09:00
|
|
|
|
2017-06-02 13:51:00 -07:00
|
|
|
"golang.org/x/sys/unix"
|
2023-06-03 14:17:16 -07:00
|
|
|
|
2024-02-17 03:48:29 +00:00
|
|
|
"github.com/shirou/gopsutil/v4/internal/common"
|
2014-11-27 10:18:15 +09:00
|
|
|
)
|
|
|
|
|
2020-10-20 18:11:00 +09:00
|
|
|
// PartitionsWithContext returns disk partition.
|
|
|
|
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
2017-12-31 15:25:49 +09:00
|
|
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
2016-03-22 23:09:12 +09:00
|
|
|
var ret []PartitionStat
|
2014-08-08 23:09:28 +09:00
|
|
|
|
2020-01-07 23:24:48 +01:00
|
|
|
count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
|
2014-12-28 22:30:07 +09:00
|
|
|
if err != nil {
|
|
|
|
return ret, err
|
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
fs := make([]unix.Statfs_t, count)
|
2022-12-07 14:31:09 +11:00
|
|
|
count, err = unix.Getfsstat(fs, unix.MNT_WAIT)
|
2022-12-07 14:27:20 +11:00
|
|
|
if err != nil {
|
2018-06-21 16:48:16 +02:00
|
|
|
return ret, err
|
|
|
|
}
|
2022-12-18 14:23:01 +11:00
|
|
|
// On 10.14, and possibly other OS versions, the actual count may
|
|
|
|
// be less than from the first call. Truncate to the returned count
|
|
|
|
// to prevent accessing uninitialized entries.
|
2022-12-18 13:11:56 +09:00
|
|
|
// https://github.com/shirou/gopsutil/issues/1390
|
2022-12-18 14:23:01 +11:00
|
|
|
fs = fs[:count]
|
2014-12-28 22:30:07 +09:00
|
|
|
for _, stat := range fs {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts := []string{"rw"}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_RDONLY != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = []string{"ro"}
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_SYNCHRONOUS != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "sync")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_NOEXEC != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "noexec")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_NOSUID != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "nosuid")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_UNION != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "union")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_ASYNC != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "async")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_DONTBROWSE != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "nobrowse")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_AUTOMOUNTED != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "automounted")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_JOURNALED != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "journaled")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_MULTILABEL != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "multilabel")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_NOATIME != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "noatime")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2020-01-07 23:24:48 +01:00
|
|
|
if stat.Flags&unix.MNT_NODEV != 0 {
|
2021-11-06 09:53:56 +00:00
|
|
|
opts = append(opts, "nodev")
|
2014-12-28 22:30:07 +09:00
|
|
|
}
|
2016-03-22 23:09:12 +09:00
|
|
|
d := PartitionStat{
|
2020-10-15 23:17:33 +02:00
|
|
|
Device: common.ByteToString(stat.Mntfromname[:]),
|
|
|
|
Mountpoint: common.ByteToString(stat.Mntonname[:]),
|
|
|
|
Fstype: common.ByteToString(stat.Fstypename[:]),
|
2014-12-28 22:30:07 +09:00
|
|
|
Opts: opts,
|
|
|
|
}
|
2016-04-16 22:43:55 +09:00
|
|
|
|
2014-12-28 22:30:07 +09:00
|
|
|
ret = append(ret, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
2014-08-08 23:09:28 +09:00
|
|
|
}
|
|
|
|
|
2017-06-02 13:51:00 -07:00
|
|
|
func getFsType(stat unix.Statfs_t) string {
|
2020-10-15 23:17:33 +02:00
|
|
|
return common.ByteToString(stat.Fstypename[:])
|
2015-08-14 18:08:43 +09:00
|
|
|
}
|
2021-11-06 09:53:56 +00:00
|
|
|
|
|
|
|
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
|
|
|
|
return "", common.ErrNotImplementedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func LabelWithContext(ctx context.Context, name string) (string, error) {
|
|
|
|
return "", common.ErrNotImplementedError
|
|
|
|
}
|