github.com/stevegt/moby@v1.13.1/pkg/mount/mounter_freebsd.go (about) 1 package mount 2 3 /* 4 #include <errno.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <sys/_iovec.h> 8 #include <sys/mount.h> 9 #include <sys/param.h> 10 */ 11 import "C" 12 13 import ( 14 "fmt" 15 "strings" 16 "syscall" 17 "unsafe" 18 ) 19 20 func allocateIOVecs(options []string) []C.struct_iovec { 21 out := make([]C.struct_iovec, len(options)) 22 for i, option := range options { 23 out[i].iov_base = unsafe.Pointer(C.CString(option)) 24 out[i].iov_len = C.size_t(len(option) + 1) 25 } 26 return out 27 } 28 29 func mount(device, target, mType string, flag uintptr, data string) error { 30 isNullFS := false 31 32 xs := strings.Split(data, ",") 33 for _, x := range xs { 34 if x == "bind" { 35 isNullFS = true 36 } 37 } 38 39 options := []string{"fspath", target} 40 if isNullFS { 41 options = append(options, "fstype", "nullfs", "target", device) 42 } else { 43 options = append(options, "fstype", mType, "from", device) 44 } 45 rawOptions := allocateIOVecs(options) 46 for _, rawOption := range rawOptions { 47 defer C.free(rawOption.iov_base) 48 } 49 50 if errno := C.nmount(&rawOptions[0], C.uint(len(options)), C.int(flag)); errno != 0 { 51 reason := C.GoString(C.strerror(*C.__error())) 52 return fmt.Errorf("Failed to call nmount: %s", reason) 53 } 54 return nil 55 } 56 57 func unmount(target string, flag int) error { 58 return syscall.Unmount(target, flag) 59 }