Debian Codegraph @

mountinfo/mountinfo_bsd.go

raw symbols SCIP
1 //go:build freebsd || openbsd || darwin
2
3 package mountinfo
4
5 import "golang.org/x/sys/unix"
6
7 // parseMountTable returns information about mounted filesystems
8 func parseMountTable(filter FilterFunc) ([]*Info, error) {
9 count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
10 if err != nil {
11 return nil, err
12 }
13
14 entries := make([]unix.Statfs_t, count)
15 _, err = unix.Getfsstat(entries, unix.MNT_WAIT)
16 if err != nil {
17 return nil, err
18 }
19
20 var out []*Info
21 for _, entry := range entries {
22 var skip, stop bool
23 mountinfo := getMountinfo(&entry)
24
25 if filter != nil {
26 // filter out entries we're not interested in
27 skip, stop = filter(mountinfo)
28 if skip {
29 continue
30 }
31 }
32
33 out = append(out, mountinfo)
34 if stop {
35 break
36 }
37 }
38 return out, nil
39 }
40
41 func mounted(path string) (bool, error) {
42 path, err := normalizePath(path)
43 if err != nil {
44 return false, err
45 }
46 // Fast path: compare st.st_dev fields.
47 // This should always work for FreeBSD and OpenBSD.
48 mounted, err := mountedByStat(path)
49 if err == nil {
50 return mounted, nil
51 }
52
53 // Fallback to parsing mountinfo
54 return mountedByMountinfo(path)
55 }