aboutsummaryrefslogtreecommitdiffhomepage
path: root/sandbox/mount.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-21 12:58:38 +0900
committerOphestra <cat@gensokyo.uk>2025-03-21 12:58:38 +0900
commita70daf22504f80c4e3dfbc2f34cf95db4dbb5879 (patch)
tree00eeed4a80dd5e6aeb34f4d7784e9e920006fb2e /sandbox/mount.go
parent632b18addd56227682ab4e29d97dcaf5d9642454 (diff)
sandbox: resolve inverted flags in op
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/mount.go')
-rw-r--r--sandbox/mount.go74
1 files changed, 7 insertions, 67 deletions
diff --git a/sandbox/mount.go b/sandbox/mount.go
index dfe9f032..bb5d6135 100644
--- a/sandbox/mount.go
+++ b/sandbox/mount.go
@@ -1,82 +1,22 @@
package sandbox
import (
- "errors"
"fmt"
"os"
- "strings"
"syscall"
)
-const (
- BindOptional = 1 << iota
- BindSource
- BindWritable
- BindDevice
-
- bindResolved
- bindAbsolute
- bindRecursive
-)
-
-func bindMount(src, dest string, flags int) error {
- target := toSysroot(dest)
- var source string
-
- if flags&BindSource != 0 {
- if flags&BindOptional != 0 {
- return msg.WrapErr(syscall.EINVAL,
- "flag source excludes optional")
- }
- } else if flags&bindResolved == 0 {
- return msg.WrapErr(syscall.EBADE,
- "flag source must be set on direct bind call")
- }
-
- if flags&bindAbsolute != 0 {
- if flags&BindSource == 0 {
- return msg.WrapErr(syscall.EINVAL,
- "flag absolute implies source")
- }
- source = src
+func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) error {
+ var mf uintptr = syscall.MS_SILENT | syscall.MS_BIND
+ mf |= flags & syscall.MS_REC
+ if eq {
+ msg.Verbosef("resolved %q flags %#x", target, mf)
} else {
- source = toHost(src)
+ msg.Verbosef("resolved %q on %q flags %#x", source, target, mf)
}
- if fi, err := os.Stat(source); err != nil {
- return msg.WrapErr(err, err.Error())
- } else if fi.IsDir() {
- if err = os.MkdirAll(target, 0755); err != nil {
- return msg.WrapErr(err, err.Error())
- }
- } else if err = ensureFile(target, 0444); err != nil {
- if errors.Is(err, syscall.EISDIR) {
- return msg.WrapErr(err,
- fmt.Sprintf("path %q is a directory", dest))
- }
- return wrapErrSuffix(err,
- fmt.Sprintf("cannot create %q:", dest))
- }
-
- var mf uintptr = syscall.MS_SILENT | syscall.MS_BIND
- if flags&bindRecursive != 0 {
- mf |= syscall.MS_REC
- }
- if flags&BindWritable == 0 {
- mf |= syscall.MS_RDONLY
- }
- if flags&BindDevice == 0 {
- mf |= syscall.MS_NODEV
- }
- if msg.IsVerbose() {
- if strings.TrimPrefix(source, hostPath) == strings.TrimPrefix(target, sysrootPath) {
- msg.Verbosef("resolved %q flags %#x", target, mf)
- } else {
- msg.Verbosef("resolved %q on %q flags %#x", source, target, mf)
- }
- }
return wrapErrSuffix(syscall.Mount(source, target, "", mf, ""),
- fmt.Sprintf("cannot bind %q on %q:", src, dest))
+ fmt.Sprintf("cannot mount %q on %q:", source, target))
}
func mountTmpfs(fsname, name string, size int, perm os.FileMode) error {