File: mountinfo_bsd.go

package info (click to toggle)
singularity-container 4.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,672 kB
  • sloc: asm: 3,857; sh: 2,125; ansic: 1,677; awk: 414; makefile: 110; python: 99
file content (56 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (5)
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
//go:build freebsd || openbsd || darwin
// +build freebsd openbsd darwin

package mountinfo

import "golang.org/x/sys/unix"

// parseMountTable returns information about mounted filesystems
func parseMountTable(filter FilterFunc) ([]*Info, error) {
	count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
	if err != nil {
		return nil, err
	}

	entries := make([]unix.Statfs_t, count)
	_, err = unix.Getfsstat(entries, unix.MNT_WAIT)
	if err != nil {
		return nil, err
	}

	var out []*Info
	for _, entry := range entries {
		var skip, stop bool
		mountinfo := getMountinfo(&entry)

		if filter != nil {
			// filter out entries we're not interested in
			skip, stop = filter(mountinfo)
			if skip {
				continue
			}
		}

		out = append(out, mountinfo)
		if stop {
			break
		}
	}
	return out, nil
}

func mounted(path string) (bool, error) {
	path, err := normalizePath(path)
	if err != nil {
		return false, err
	}
	// Fast path: compare st.st_dev fields.
	// This should always work for FreeBSD and OpenBSD.
	mounted, err := mountedByStat(path)
	if err == nil {
		return mounted, nil
	}

	// Fallback to parsing mountinfo
	return mountedByMountinfo(path)
}