diffs and relevant changes: docker/docker:c2cc352355...af34b94a78- replace pkg/symlink with github.com/moby/sys/symlink moby/sys:6154f11e68...1bc8673b57changes: - mount, mountinfo: Add support for OpenBSD in addition to FreeBSD - mount, mountinfo: Exclude macOS (darwin) - mount.RecursiveUnmount(): minor improvements - mount.RecursiveUnmount: add a fast path - mount: bump mountinfo to v0.3.1 - mount: Some refactor and improved GoDoc about Windows support - mount: use MNT_* flags from golang.org/x/sys/unix on freebsd (reduces use of cgo) - mountinfo.Mounted: add fast path for Linux using openat2 - mountinfo.Mounted: optimize by adding fast paths - mountinfo: correctness improvements - mountinfo: deprecate PidMountInfo - mountinfo: fix not showing package doc, typos - mountinfo: fix path unescaping - mountinfo: make GetMountinfoFromReader Linux-specific - mountinfo: rename FstypeFilter -> FSTypeFilter, fix FilterFunc docs - mountinfo: use idiomatic naming for fields - Migrate github.com/docker/docker/pkg/symlink Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
// +build freebsd,cgo openbsd,cgo
|
|
|
|
package mount
|
|
|
|
/*
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/_iovec.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/param.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"strings"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func allocateIOVecs(options []string) []C.struct_iovec {
|
|
out := make([]C.struct_iovec, len(options))
|
|
for i, option := range options {
|
|
out[i].iov_base = unsafe.Pointer(C.CString(option))
|
|
out[i].iov_len = C.size_t(len(option) + 1)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func mount(device, target, mType string, flag uintptr, data string) error {
|
|
isNullFS := false
|
|
|
|
xs := strings.Split(data, ",")
|
|
for _, x := range xs {
|
|
if x == "bind" {
|
|
isNullFS = true
|
|
}
|
|
}
|
|
|
|
options := []string{"fspath", target}
|
|
if isNullFS {
|
|
options = append(options, "fstype", "nullfs", "target", device)
|
|
} else {
|
|
options = append(options, "fstype", mType, "from", device)
|
|
}
|
|
rawOptions := allocateIOVecs(options)
|
|
for _, rawOption := range rawOptions {
|
|
defer C.free(rawOption.iov_base)
|
|
}
|
|
|
|
if errno := C.nmount(&rawOptions[0], C.uint(len(options)), C.int(flag)); errno != 0 {
|
|
return &mountError{
|
|
op: "mount",
|
|
source: device,
|
|
target: target,
|
|
flags: flag,
|
|
err: syscall.Errno(errno),
|
|
}
|
|
}
|
|
return nil
|
|
}
|