-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfs_utils_linux.go
56 lines (48 loc) · 1.44 KB
/
fs_utils_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"os/exec"
"strings"
log "github.com/sirupsen/logrus"
)
// Format calls mke2fs on path
func Format(path string, formatFSType string) error {
cmd := exec.Command("mkfs", "-t", formatFSType, path)
stdOutAndErr, err := cmd.CombinedOutput()
log.Debugf("Mke2fs Output:\n%s", stdOutAndErr)
return err
}
// Mount mounts device to mountpoint
func Mount(device string, mountpoint string) error {
log.Debugf("calling mount %s %s", device, mountpoint)
cmd := exec.Command("mount", device, mountpoint)
output, err := cmd.CombinedOutput()
log.Debugf("Mount Output:\n%s", string(output))
return err
}
// Umount calls umount command
func Umount(mountpoint string) error {
cmd := exec.Command("umount", mountpoint)
output, err := cmd.CombinedOutput()
log.Debugf("Umount Output:\n%s", string(output))
return err
}
// GetFSType returns the filesystem type from a block device
// function based on https://github.com/yholkamp/ovh-docker-volume-plugin/blob/master/utils.go
func GetFSType(device string) string {
log.Infof("GetFSType(%s)", device)
fsType := ""
out, err := exec.Command("blkid", device).CombinedOutput()
if err != nil {
return fsType
}
if strings.Contains(string(out), "TYPE=") {
for _, v := range strings.Split(string(out), " ") {
if strings.Contains(v, "TYPE=") {
fsType = strings.Split(v, "=")[1]
fsType = strings.Replace(fsType, "\"", "", -1)
}
}
}
log.Infof("GetFSType(): %s", fsType)
return fsType
}