github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/pkg/mount/mountinfo_freebsd.go (about) 1 package mount // import "github.com/docker/docker/pkg/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(filter FilterFunc) ([]*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 var skip, stop bool 36 mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0]) 37 38 if filter != nil { 39 // filter out entries we're not interested in 40 skip, stop = filter(p) 41 if skip { 42 continue 43 } 44 } 45 46 mountinfo.Source = C.GoString(&entry.f_mntfromname[0]) 47 mountinfo.Fstype = C.GoString(&entry.f_fstypename[0]) 48 49 out = append(out, &mountinfo) 50 if stop { 51 break 52 } 53 } 54 return out, nil 55 }