aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/inittmpfs.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-20 01:26:41 +0900
committerOphestra <cat@gensokyo.uk>2025-08-20 01:28:31 +0900
commitc81c9a9d75f179988cf858b85fe2de71bf9c2ff4 (patch)
tree157723a3f9a6f8a456fc939a1ef56e8e597d70f3 /container/inittmpfs.go
parent339e4080dce73d372f6111773066b9c84308b6b7 (diff)
container/init: split setup ops into individual files
This significantly increases readability. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/inittmpfs.go')
-rw-r--r--container/inittmpfs.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/container/inittmpfs.go b/container/inittmpfs.go
new file mode 100644
index 00000000..d4f03237
--- /dev/null
+++ b/container/inittmpfs.go
@@ -0,0 +1,47 @@
+package container
+
+import (
+ "encoding/gob"
+ "fmt"
+ "math"
+ "os"
+ . "syscall"
+)
+
+func init() { gob.Register(new(MountTmpfsOp)) }
+
+// Tmpfs appends an [Op] that mounts tmpfs on container path [MountTmpfsOp.Path].
+func (f *Ops) Tmpfs(target *Absolute, size int, perm os.FileMode) *Ops {
+ *f = append(*f, &MountTmpfsOp{SourceTmpfsEphemeral, target, MS_NOSUID | MS_NODEV, size, perm})
+ return f
+}
+
+// Readonly appends an [Op] that mounts read-only tmpfs on container path [MountTmpfsOp.Path].
+func (f *Ops) Readonly(target *Absolute, perm os.FileMode) *Ops {
+ *f = append(*f, &MountTmpfsOp{SourceTmpfsReadonly, target, MS_RDONLY | MS_NOSUID | MS_NODEV, 0, perm})
+ return f
+}
+
+// MountTmpfsOp mounts [FstypeTmpfs] on container Path.
+type MountTmpfsOp struct {
+ FSName string
+ Path *Absolute
+ Flags uintptr
+ Size int
+ Perm os.FileMode
+}
+
+func (t *MountTmpfsOp) early(*setupState) error { return nil }
+func (t *MountTmpfsOp) apply(*setupState) error {
+ if t.Path == nil {
+ return EBADE
+ }
+ if t.Size < 0 || t.Size > math.MaxUint>>1 {
+ return msg.WrapErr(EBADE, fmt.Sprintf("size %d out of bounds", t.Size))
+ }
+ return mountTmpfs(t.FSName, toSysroot(t.Path.String()), t.Flags, t.Size, t.Perm)
+}
+
+func (t *MountTmpfsOp) Is(op Op) bool { vt, ok := op.(*MountTmpfsOp); return ok && *t == *vt }
+func (*MountTmpfsOp) prefix() string { return "mounting" }
+func (t *MountTmpfsOp) String() string { return fmt.Sprintf("tmpfs on %q size %d", t.Path, t.Size) }