sharedsubtree_linux.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // +build linux
  2. package mount
  3. // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
  4. // See the supported options in flags.go for further reference.
  5. func MakeShared(mountPoint string) error {
  6. return ensureMountedAs(mountPoint, "shared")
  7. }
  8. // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
  9. // See the supported options in flags.go for further reference.
  10. func MakeRShared(mountPoint string) error {
  11. return ensureMountedAs(mountPoint, "rshared")
  12. }
  13. // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
  14. // See the supported options in flags.go for further reference.
  15. func MakePrivate(mountPoint string) error {
  16. return ensureMountedAs(mountPoint, "private")
  17. }
  18. // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
  19. // enabled. See the supported options in flags.go for further reference.
  20. func MakeRPrivate(mountPoint string) error {
  21. return ensureMountedAs(mountPoint, "rprivate")
  22. }
  23. // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
  24. // See the supported options in flags.go for further reference.
  25. func MakeSlave(mountPoint string) error {
  26. return ensureMountedAs(mountPoint, "slave")
  27. }
  28. // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
  29. // See the supported options in flags.go for further reference.
  30. func MakeRSlave(mountPoint string) error {
  31. return ensureMountedAs(mountPoint, "rslave")
  32. }
  33. // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
  34. // enabled. See the supported options in flags.go for further reference.
  35. func MakeUnbindable(mountPoint string) error {
  36. return ensureMountedAs(mountPoint, "unbindable")
  37. }
  38. // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
  39. // option enabled. See the supported options in flags.go for further reference.
  40. func MakeRUnbindable(mountPoint string) error {
  41. return ensureMountedAs(mountPoint, "runbindable")
  42. }
  43. func ensureMountedAs(mountPoint, options string) error {
  44. mounted, err := Mounted(mountPoint)
  45. if err != nil {
  46. return err
  47. }
  48. if !mounted {
  49. if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
  50. return err
  51. }
  52. }
  53. if _, err = Mounted(mountPoint); err != nil {
  54. return err
  55. }
  56. return ForceMount("", mountPoint, "none", options)
  57. }