From 5d9e669d97ee53e3b6d4478d315319b59d5b402b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 14 Mar 2025 00:21:20 +0900 Subject: sandbox: separate tmpfs function from op This is useful in the implementation of various other ops. Signed-off-by: Ophestra --- internal/sandbox/sequential.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'internal/sandbox/sequential.go') diff --git a/internal/sandbox/sequential.go b/internal/sandbox/sequential.go index d4a29fa5..445ae8f8 100644 --- a/internal/sandbox/sequential.go +++ b/internal/sandbox/sequential.go @@ -75,7 +75,7 @@ func init() { gob.Register(new(MountTmpfs)) } type MountTmpfs struct { Path string Size int - Mode os.FileMode + Perm os.FileMode } func (t *MountTmpfs) apply() error { @@ -87,22 +87,12 @@ func (t *MountTmpfs) apply() error { return fmsg.WrapError(syscall.EBADE, fmt.Sprintf("size %d out of bounds", t.Size)) } - target := toSysroot(t.Path) - if err := os.MkdirAll(target, 0755); err != nil { - return err - } - opt := fmt.Sprintf("mode=%#o", t.Mode) - if t.Size > 0 { - opt += fmt.Sprintf(",size=%d", t.Mode) - } - return fmsg.WrapErrorSuffix(syscall.Mount("tmpfs", target, "tmpfs", - syscall.MS_NOSUID|syscall.MS_NODEV, opt), - fmt.Sprintf("cannot mount tmpfs on %q:", t.Path)) + return mountTmpfs(t.Path, t.Size, t.Perm) } func (t *MountTmpfs) Is(op Op) bool { vt, ok := op.(*MountTmpfs); return ok && *t == *vt } func (t *MountTmpfs) String() string { return fmt.Sprintf("tmpfs on %q size %d", t.Path, t.Size) } -func (f *Ops) Tmpfs(dest string, size int, mode os.FileMode) *Ops { - *f = append(*f, &MountTmpfs{dest, size, mode}) +func (f *Ops) Tmpfs(dest string, size int, perm os.FileMode) *Ops { + *f = append(*f, &MountTmpfs{dest, size, perm}) return f } -- cgit v1.3.1