aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/initremount.go
blob: 77efc21d321381d8531c47a48457565f2b92154b (plain)
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
package container

import (
	"encoding/gob"
	"fmt"
	"syscall"
)

func init() { gob.Register(new(RemountOp)) }

// Remount appends an [Op] that applies [RemountOp.Flags] on container path [RemountOp.Target].
func (f *Ops) Remount(target *Absolute, flags uintptr) *Ops {
	*f = append(*f, &RemountOp{target, flags})
	return f
}

// RemountOp remounts Target with Flags.
type RemountOp struct {
	Target *Absolute
	Flags  uintptr
}

func (*RemountOp) early(*setupState) error { return nil }
func (r *RemountOp) apply(*setupState) error {
	if r.Target == nil {
		return syscall.EBADE
	}
	return wrapErrSuffix(hostProc.remount(toSysroot(r.Target.String()), r.Flags),
		fmt.Sprintf("cannot remount %q:", r.Target))
}

func (r *RemountOp) Is(op Op) bool {
	vr, ok := op.(*RemountOp)
	return ok && ((r == nil && vr == nil) ||
		(r.Target != nil && vr.Target != nil && r.Target.Is(vr.Target)) &&
			r.Flags == vr.Flags)
}
func (*RemountOp) prefix() string   { return "remounting" }
func (r *RemountOp) String() string { return fmt.Sprintf("%q flags %#x", r.Target, r.Flags) }