-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmount_arg.go
71 lines (67 loc) · 1.53 KB
/
mount_arg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ginit
import (
"fmt"
"golang.org/x/sys/unix"
"os"
"path/filepath"
)
// Bind returns arguments for perofmring a Bind mount.
func Bind(path string, readOnly bool) MountArgs {
var flags uintptr
if readOnly {
flags = unix.MS_BIND | unix.MS_RDONLY
} else {
flags = unix.MS_BIND
}
return MountArgs{
Source: path,
Target: path,
Flags: flags,
}
}
// Overlay returns options for performing
// an OverlayFS mount.
func Overlay(lower, target string) MountArgs {
upper := filepath.Join(filepath.Dir(lower), "upper")
work := filepath.Join(filepath.Dir(lower), "work")
return MountArgs{
Before: func() (err error) {
err = os.MkdirAll(upper, 0755)
if err != nil {
return err
}
err = os.MkdirAll(work, 0755)
if err != nil {
return err
}
return nil
},
Source: "overlay",
Target: target,
FSType: "overlay",
Flags: 0,
Data: fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lower, upper, work),
}
}
// TmpFS return options for performing a tmpfs mount
// at the given path percentage must be between 0
// and 100 or we will panic. If it is zero we do
// not specify any flags.
func TmpFS(path string, percentage int) MountArgs {
if percentage < 0 || percentage > 100 {
panic("invalid tempfs percentage")
}
var data string
if percentage > 0 {
data = fmt.Sprintf("%d", percentage)
}
return MountArgs{
Before: func() error {
return os.MkdirAll(path, 0755)
},
Source: "rootfs", // TODO: Unsure if this has significance with tempfs
Target: path,
FSType: "tmpfs",
Data: data,
}
}