diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-03-14 00:21:20 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-03-14 00:21:20 +0900 |
| commit | 5d9e669d97ee53e3b6d4478d315319b59d5b402b (patch) | |
| tree | e601580ad066b4054e773d473e8a3af2f1176c07 /internal/sandbox/mount.go | |
| parent | f1002157a58a5a0a559ba9295c3193c300a4235d (diff) | |
sandbox: separate tmpfs function from op
This is useful in the implementation of various other ops.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/sandbox/mount.go')
| -rw-r--r-- | internal/sandbox/mount.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/sandbox/mount.go b/internal/sandbox/mount.go index 3c6ae2d8..3d3d63af 100644 --- a/internal/sandbox/mount.go +++ b/internal/sandbox/mount.go @@ -79,3 +79,17 @@ func bindMount(src, dest string, flags int) error { return fmsg.WrapErrorSuffix(syscall.Mount(source, target, "", mf, ""), fmt.Sprintf("cannot bind %q on %q:", src, dest)) } + +func mountTmpfs(name string, size int, perm os.FileMode) error { + target := toSysroot(name) + if err := os.MkdirAll(target, perm); err != nil { + return err + } + opt := fmt.Sprintf("mode=%#o", perm) + if size > 0 { + opt += fmt.Sprintf(",size=%d", size) + } + return fmsg.WrapErrorSuffix(syscall.Mount("tmpfs", target, "tmpfs", + syscall.MS_NOSUID|syscall.MS_NODEV, opt), + fmt.Sprintf("cannot mount tmpfs on %q:", name)) +} |
