func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
	s := bufio.NewScanner(r)
	out := []*Info{}
	for s.Scan() {
		var err error
		text := s.Text()
		fields := strings.Split(text, " ")
		numFields := len(fields)
		if numFields < 10 {
			return nil, fmt.Errorf("parsing '%s' failed: not enough fields (%d)", text, numFields)
		}
		sepIdx := numFields - 4
		for fields[sepIdx] != "-" {
			sepIdx--
			if sepIdx == 5 {
				return nil, fmt.Errorf("parsing '%s' failed: missing - separator", text)
			}
		}
		p := &Info{}
		p.Mountpoint, err = unescape(fields[4])
		if err != nil {
			return nil, fmt.Errorf("parsing '%s' failed: mount point: %w", fields[4], err)
		}
		p.FSType, err = unescape(fields[sepIdx+1])
		if err != nil {
			return nil, fmt.Errorf("parsing '%s' failed: fstype: %w", fields[sepIdx+1], err)
		}
		p.Source, err = unescape(fields[sepIdx+2])
		if err != nil {
			return nil, fmt.Errorf("parsing '%s' failed: source: %w", fields[sepIdx+2], err)
		}
		p.VFSOptions = fields[sepIdx+3]
		p.ID, _ = strconv.Atoi(fields[0])
		p.Parent, _ = strconv.Atoi(fields[1])
		mm := strings.SplitN(fields[2], ":", 3)
		if len(mm) != 2 {
			return nil, fmt.Errorf("parsing '%s' failed: unexpected major:minor pair %s", text, mm)
		}
		p.Major, _ = strconv.Atoi(mm[0])
		p.Minor, _ = strconv.Atoi(mm[1])
		p.Root, err = unescape(fields[3])
		if err != nil {
			return nil, fmt.Errorf("parsing '%s' failed: root: %w", fields[3], err)
		}
		p.Options = fields[5]
		p.Optional = strings.Join(fields[6:sepIdx], " ")
		var skip, stop bool
		if filter != nil {
			skip, stop = filter(p)
			if skip {
				continue
			}
		}
		out = append(out, p)
		if stop {
			break
		}
	}
	if err := s.Err(); err != nil {
		return nil, err
	}
	return out, nil
}
GetMountsFromReader retrieves a list of mounts from the
reader provided, with an optional filter applied (use nil
for no filter). This can be useful in tests or benchmarks
that provide fake mountinfo data, or when a source other
than /proc/self/mountinfo needs to be read from.

This function is Linux-specific.
package mountinfo
import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)