forked from perkeep/perkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mountinfo_linux.go
57 lines (52 loc) · 1.19 KB
/
mountinfo_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
57
package fstestutil
import (
"errors"
"camlistore.org/third_party/github.com/artyom/mtab"
)
// Inventory of mount information parsing packages out there:
//
// https://github.com/cratonica/gomounts
//
// Does it "right" by using getmntent(3), but that needs CGo which
// prevents cross-compiling easily.
//
// https://github.com/antage/mntent
//
// Does not handle escaping at all.
//
// https://github.com/deniswernert/go-fstab
//
// Does not handle escaping at all. Has trivial bugs like
// https://github.com/deniswernert/go-fstab/issues/1
//
// http://godoc.org/github.com/docker/docker/pkg/mount
//
// Does not handle escaping at all. Part of an overly large source
// tree.
//
// https://github.com/artyom/mtab
//
// Does not split options. Otherwise seems to work.
func findMount(mnt string) (*mtab.Entry, error) {
mounts, err := mtab.Entries("/proc/mounts")
if err != nil {
return nil, err
}
for _, m := range mounts {
if m.Dir == mnt {
return &m, nil
}
}
return nil, errors.New("mount not found")
}
func getMountInfo(mnt string) (*MountInfo, error) {
m, err := findMount(mnt)
if err != nil {
return nil, err
}
i := &MountInfo{
FSName: m.Fsname,
Type: m.Type,
}
return i, nil
}