diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-01 23:48:02 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-01 23:48:02 +0900 |
| commit | c5d24979f5d6095116d66beb544aa382816183f9 (patch) | |
| tree | a150559abaea01bf9b103be234e85e04e1a04c7c /container/ops.go | |
| parent | 1dc780bca737610196ed58644b3ba61edc8acc48 (diff) | |
container/ops: expose remount as Op
This is useful for building a filesystem hierarchy then remounting it readonly.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/ops.go')
| -rw-r--r-- | container/ops.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/container/ops.go b/container/ops.go index 1fd4963c..7456ed38 100644 --- a/container/ops.go +++ b/container/ops.go @@ -33,6 +33,32 @@ type ( // Grow grows the slice Ops points to using [slices.Grow]. func (f *Ops) Grow(n int) { *f = slices.Grow(*f, n) } +func init() { gob.Register(new(RemountOp)) } + +// Remount appends an [Op] that applies [RemountOp.Flags] on container path [RemountOp.Target]. +func (f *Ops) Remount(target string, flags uintptr) *Ops { + *f = append(*f, &RemountOp{target, flags}) + return f +} + +type RemountOp struct { + Target string + Flags uintptr +} + +func (*RemountOp) early(*Params) error { return nil } +func (r *RemountOp) apply(*Params) error { + if !path.IsAbs(r.Target) { + return msg.WrapErr(EBADE, fmt.Sprintf("path %q is not absolute", r.Target)) + } + return wrapErrSuffix(hostProc.remount(toSysroot(r.Target), r.Flags), + fmt.Sprintf("cannot remount %q:", r.Target)) +} + +func (r *RemountOp) Is(op Op) bool { vr, ok := op.(*RemountOp); return ok && *r == *vr } +func (*RemountOp) prefix() string { return "remounting" } +func (r *RemountOp) String() string { return fmt.Sprintf("%q flags %#x", r.Target, r.Flags) } + func init() { gob.Register(new(BindMountOp)) } // Bind appends an [Op] that bind mounts host path [BindMountOp.Source] on container path [BindMountOp.Target]. |
