diskspace/mount.go

33 lines
554 B
Go
Raw Normal View History

2022-06-28 13:11:16 +02:00
package main
import (
"bufio"
"bytes"
"os/exec"
"regexp"
)
var (
mountLineRegex = regexp.MustCompile(`^.*? on (.*?) type (.*?) \((?:.*?[,)])*$`)
)
func Mounts() (map[string]struct{}, error) {
mounts := map[string]struct{}{}
out, err := exec.Command("mount").CombinedOutput()
if err != nil {
return nil, err
}
s := bufio.NewScanner(bytes.NewReader(out))
for s.Scan() {
matches := mountLineRegex.FindAllStringSubmatch(s.Text(), -1)
if len(matches) == 0 {
continue
}
mounts[matches[0][1]] = struct{}{}
}
return mounts, nil
}