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

import (
	"encoding/gob"
	"fmt"

	"hakurei.app/check"
)

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

// Remount is a helper for appending [RemountOp] to [Ops].
func (f *Ops) Remount(target *check.Absolute, flags uintptr) *Ops {
	*f = append(*f, &RemountOp{target, flags})
	return f
}

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

func (r *RemountOp) Valid() bool                              { return r != nil && r.Target != nil }
func (*RemountOp) early(*setupState, syscallDispatcher) error { return nil }
func (r *RemountOp) apply(state *setupState, k syscallDispatcher) error {
	return k.remount(state, toSysroot(r.Target.String()), r.Flags)
}
func (r *RemountOp) late(*setupState, syscallDispatcher) error { return nil }

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