github.com/slava-ustovytski/docker@v1.8.2-rc1/pkg/mount/mountinfo_freebsd.go (about)

     1  package mount
     2  
     3  /*
     4  #include <sys/param.h>
     5  #include <sys/ucred.h>
     6  #include <sys/mount.h>
     7  */
     8  import "C"
     9  
    10  import (
    11  	"fmt"
    12  	"reflect"
    13  	"unsafe"
    14  )
    15  
    16  // Parse /proc/self/mountinfo because comparing Dev and ino does not work from
    17  // bind mounts.
    18  func parseMountTable() ([]*Info, error) {
    19  	var rawEntries *C.struct_statfs
    20  
    21  	count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT))
    22  	if count == 0 {
    23  		return nil, fmt.Errorf("Failed to call getmntinfo")
    24  	}
    25  
    26  	var entries []C.struct_statfs
    27  	header := (*reflect.SliceHeader)(unsafe.Pointer(&entries))
    28  	header.Cap = count
    29  	header.Len = count
    30  	header.Data = uintptr(unsafe.Pointer(rawEntries))
    31  
    32  	var out []*Info
    33  	for _, entry := range entries {
    34  		var mountinfo Info
    35  		mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
    36  		mountinfo.Source = C.GoString(&entry.f_mntfromname[0])
    37  		mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
    38  		out = append(out, &mountinfo)
    39  	}
    40  	return out, nil
    41  }