2014-10-30 17:04:56 -04:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package mount
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeShared(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "shared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRShared(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rshared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-30 17:04:56 -04:00
|
|
|
func MakePrivate(mountPoint string) error {
|
2014-10-31 10:18:41 -04:00
|
|
|
return ensureMountedAs(mountPoint, "private")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
|
|
|
|
// enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRPrivate(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rprivate")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeSlave(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "slave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
|
|
|
|
// See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRSlave(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rslave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
|
|
|
|
// enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeUnbindable(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "unbindable")
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
|
|
|
|
// option enabled. See the supported options in flags.go for further reference.
|
2014-10-31 10:18:41 -04:00
|
|
|
func MakeRUnbindable(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "runbindable")
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureMountedAs(mountPoint, options string) error {
|
2014-10-30 17:04:56 -04:00
|
|
|
mounted, err := Mounted(mountPoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !mounted {
|
|
|
|
if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 22:43:26 -04:00
|
|
|
if _, err = Mounted(mountPoint); err != nil {
|
2014-10-31 10:18:41 -04:00
|
|
|
return err
|
|
|
|
}
|
2014-10-30 17:04:56 -04:00
|
|
|
|
2014-10-31 10:18:41 -04:00
|
|
|
return ForceMount("", mountPoint, "none", options)
|
2014-10-30 17:04:56 -04:00
|
|
|
}
|