...
1
2
3
4 package mountinfo
5
6 import "golang.org/x/sys/unix"
7
8
9 func parseMountTable(filter FilterFunc) ([]*Info, error) {
10 count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
11 if err != nil {
12 return nil, err
13 }
14
15 entries := make([]unix.Statfs_t, count)
16 _, err = unix.Getfsstat(entries, unix.MNT_WAIT)
17 if err != nil {
18 return nil, err
19 }
20
21 var out []*Info
22 for _, entry := range entries {
23 var skip, stop bool
24 mountinfo := getMountinfo(&entry)
25
26 if filter != nil {
27
28 skip, stop = filter(mountinfo)
29 if skip {
30 continue
31 }
32 }
33
34 out = append(out, mountinfo)
35 if stop {
36 break
37 }
38 }
39 return out, nil
40 }
41
42 func mounted(path string) (bool, error) {
43 path, err := normalizePath(path)
44 if err != nil {
45 return false, err
46 }
47
48
49 mounted, err := mountedByStat(path)
50 if err == nil {
51 return mounted, nil
52 }
53
54
55 return mountedByMountinfo(path)
56 }
57
View as plain text