-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmount.go
44 lines (38 loc) · 892 Bytes
/
mount.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
package ginit
import (
"golang.org/x/sys/unix"
)
// Option is a functional option to modify MountArgs.
type MountOption func(MountArgs) MountArgs
// MountArgs hold arguments for making
// unix.Mount syscalls.
type MountArgs struct {
Source string
Target string
FSType string
Flags uintptr
// mount -o options
// TODO: Make strongly typed.
Data string
Before func() error
}
// Mount performs the unix.Mount syscall
func Mount(args MountArgs, opts ...MountOption) error {
for _, opt := range opts {
args = opt(args)
}
if args.Before != nil {
err := args.Before()
if err != nil {
return err
}
}
return unix.Mount(args.Source, args.Target, args.FSType, args.Flags, args.Data)
}
// MustMount performs a unix.Mount syscall and panics on failure.
func MustMount(args MountArgs, opts ...MountOption) {
err := Mount(args, opts...)
if err != nil {
panic(err)
}
}