33 lines
554 B
Go
33 lines
554 B
Go
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
|
|
}
|