github.com/dlintw/docker@v1.5.0-rc4/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 bind mounts
    17  func parseMountTable() ([]*MountInfo, error) {
    18  	var rawEntries *C.struct_statfs
    19  
    20  	count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT))
    21  	if count == 0 {
    22  		return nil, fmt.Errorf("Failed to call getmntinfo")
    23  	}
    24  
    25  	var entries []C.struct_statfs
    26  	header := (*reflect.SliceHeader)(unsafe.Pointer(&entries))
    27  	header.Cap = count
    28  	header.Len = count
    29  	header.Data = uintptr(unsafe.Pointer(rawEntries))
    30  
    31  	var out []*MountInfo
    32  	for _, entry := range entries {
    33  		var mountinfo MountInfo
    34  		mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
    35  		mountinfo.Source = C.GoString(&entry.f_mntfromname[0])
    36  		mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
    37  		out = append(out, &mountinfo)
    38  	}
    39  	return out, nil
    40  }