Debian Codegraph @

mount/sharedsubtree_linux.go

raw symbols SCIP
1 package mount
2
3 import "github.com/moby/sys/mountinfo"
4
5 // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
6 // See the supported options in flags.go for further reference.
7 func MakeShared(mountPoint string) error {
8 return ensureMountedAs(mountPoint, SHARED)
9 }
10
11 // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
12 // See the supported options in flags.go for further reference.
13 func MakeRShared(mountPoint string) error {
14 return ensureMountedAs(mountPoint, RSHARED)
15 }
16
17 // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
18 // See the supported options in flags.go for further reference.
19 func MakePrivate(mountPoint string) error {
20 return ensureMountedAs(mountPoint, PRIVATE)
21 }
22
23 // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
24 // enabled. See the supported options in flags.go for further reference.
25 func MakeRPrivate(mountPoint string) error {
26 return ensureMountedAs(mountPoint, RPRIVATE)
27 }
28
29 // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
30 // See the supported options in flags.go for further reference.
31 func MakeSlave(mountPoint string) error {
32 return ensureMountedAs(mountPoint, SLAVE)
33 }
34
35 // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
36 // See the supported options in flags.go for further reference.
37 func MakeRSlave(mountPoint string) error {
38 return ensureMountedAs(mountPoint, RSLAVE)
39 }
40
41 // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
42 // enabled. See the supported options in flags.go for further reference.
43 func MakeUnbindable(mountPoint string) error {
44 return ensureMountedAs(mountPoint, UNBINDABLE)
45 }
46
47 // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
48 // option enabled. See the supported options in flags.go for further reference.
49 func MakeRUnbindable(mountPoint string) error {
50 return ensureMountedAs(mountPoint, RUNBINDABLE)
51 }
52
53 // MakeMount ensures that the file or directory given is a mount point,
54 // bind mounting it to itself it case it is not.
55 func MakeMount(mnt string) error {
56 mounted, err := mountinfo.Mounted(mnt)
57 if err != nil {
58 return err
59 }
60 if mounted {
61 return nil
62 }
63
64 return mount(mnt, mnt, "none", uintptr(BIND), "")
65 }
66
67 func ensureMountedAs(mnt string, flags int) error {
68 if err := MakeMount(mnt); err != nil {
69 return err
70 }
71
72 return mount("", mnt, "none", uintptr(flags), "")
73 }