34 lines
671 B
Go
34 lines
671 B
Go
//go:build linux
|
|
|
|
package platform
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
const ioctlLoopChangeFD = 0x4C08
|
|
|
|
func loopChangeFD(loopDev, newFile string) error {
|
|
lf, err := os.OpenFile(loopDev, os.O_RDWR, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer lf.Close()
|
|
nf, err := os.OpenFile(newFile, os.O_RDONLY, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer nf.Close()
|
|
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, lf.Fd(), ioctlLoopChangeFD, nf.Fd())
|
|
if errno != 0 {
|
|
return errno
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// bindMount binds src over dst using the syscall directly (avoids exec PATH issues).
|
|
func bindMount(src, dst string) error {
|
|
return syscall.Mount(src, dst, "", syscall.MS_BIND, "")
|
|
}
|