2021-10-01 13:59:55 +00:00
|
|
|
//go:build linux
|
2020-01-29 11:35:35 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
2022-01-14 15:46:06 +00:00
|
|
|
"github.com/moby/sys/mount"
|
|
|
|
"github.com/moby/sys/mountinfo"
|
2020-01-29 11:35:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// mounter provides the default implementation of mount.Mounter
|
|
|
|
// for the linux platform.
|
|
|
|
// Currently it delegates to the docker `mount` package.
|
|
|
|
type mounter struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a Mounter for the current system.
|
|
|
|
func New() Mounter {
|
|
|
|
return &mounter{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsNotAMountPoint determines if a directory is not a mountpoint.
|
|
|
|
// It does this by checking the path against the contents of /proc/self/mountinfo
|
|
|
|
func (m *mounter) IsNotAMountPoint(path string) (bool, error) {
|
2022-01-14 15:46:06 +00:00
|
|
|
isMount, err := mountinfo.Mounted(path)
|
2020-01-29 11:35:35 +00:00
|
|
|
return !isMount, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mounter) Mount(device, target, mountType, options string) error {
|
|
|
|
// Defer to the docker implementation of `Mount`, it's correct enough for our
|
|
|
|
// usecase and avoids us needing to shell out to the `mount` utility.
|
2022-01-14 15:46:06 +00:00
|
|
|
return mount.Mount(device, target, mountType, options)
|
2020-01-29 11:35:35 +00:00
|
|
|
}
|