2014-10-30 21:04:56 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package mount
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeShared(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "shared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeRShared(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rshared")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 21:04:56 +00:00
|
|
|
func MakePrivate(mountPoint string) error {
|
2014-10-31 14:18:41 +00:00
|
|
|
return ensureMountedAs(mountPoint, "private")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeRPrivate(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rprivate")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeSlave(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "slave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeRSlave(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "rslave")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeUnbindable(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "unbindable")
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:29:33 +00: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 14:18:41 +00:00
|
|
|
func MakeRUnbindable(mountPoint string) error {
|
|
|
|
return ensureMountedAs(mountPoint, "runbindable")
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureMountedAs(mountPoint, options string) error {
|
2014-10-30 21:04:56 +00:00
|
|
|
mounted, err := Mounted(mountPoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !mounted {
|
|
|
|
if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 14:18:41 +00:00
|
|
|
mounted, err = Mounted(mountPoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-10-30 21:04:56 +00:00
|
|
|
|
2014-10-31 14:18:41 +00:00
|
|
|
return ForceMount("", mountPoint, "none", options)
|
2014-10-30 21:04:56 +00:00
|
|
|
}
|