disk_linux.go 590 字节
Newer Older
W
WAKAYAMA Shirou 已提交
1 2 3 4
// +build linux

package gopsutil

5 6 7 8 9 10 11 12 13 14
import (
	"strings"
)

const(
	MNT_WAIT   = 1
)

// Get disk partitions.
// should use setmntent(3) but this implement use /etc/mtab file
15
func Disk_partitions(all bool) ([]Disk_partitionStat, error) {
W
WAKAYAMA Shirou 已提交
16 17
	ret := make([]Disk_partitionStat, 0)

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	filename := "/etc/mtab"
	lines, err := ReadLines(filename)
	if err != nil{
		return ret, err
	}

	for _, line := range lines{
		fields := strings.Fields(line)
		d := Disk_partitionStat{
			Mountpoint: fields[1],
			Fstype:     fields[2],
			Opts:       fields[3],
		}
		ret = append(ret, d)
	}

W
WAKAYAMA Shirou 已提交
34 35
	return ret, nil
}