2018-02-05 16:05:59 -05:00
|
|
|
package mount // import "github.com/docker/docker/pkg/mount"
|
2014-03-20 11:52:12 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2015-03-28 09:29:33 -04:00
|
|
|
// Parse /proc/self/mountinfo because comparing Dev and ino does not work from
|
|
|
|
// bind mounts.
|
2018-01-19 14:56:32 -05:00
|
|
|
func parseMountTable(filter FilterFunc) ([]*Info, error) {
|
2014-03-20 11:52:12 -04:00
|
|
|
var rawEntries *C.struct_statfs
|
|
|
|
|
|
|
|
count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT))
|
|
|
|
if count == 0 {
|
|
|
|
return nil, fmt.Errorf("Failed to call getmntinfo")
|
|
|
|
}
|
|
|
|
|
|
|
|
var entries []C.struct_statfs
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(&entries))
|
|
|
|
header.Cap = count
|
|
|
|
header.Len = count
|
|
|
|
header.Data = uintptr(unsafe.Pointer(rawEntries))
|
|
|
|
|
2015-07-21 13:49:42 -04:00
|
|
|
var out []*Info
|
2014-03-20 11:52:12 -04:00
|
|
|
for _, entry := range entries {
|
2015-07-21 13:49:42 -04:00
|
|
|
var mountinfo Info
|
2018-01-19 14:56:32 -05:00
|
|
|
var skip, stop bool
|
2014-03-20 11:52:12 -04:00
|
|
|
mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
|
2018-01-19 14:56:32 -05:00
|
|
|
|
|
|
|
if filter != nil {
|
|
|
|
// filter out entries we're not interested in
|
|
|
|
skip, stop = filter(p)
|
|
|
|
if skip {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 14:01:50 -05:00
|
|
|
mountinfo.Source = C.GoString(&entry.f_mntfromname[0])
|
|
|
|
mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
|
2018-01-19 14:56:32 -05:00
|
|
|
|
2014-03-20 11:52:12 -04:00
|
|
|
out = append(out, &mountinfo)
|
2018-01-19 14:56:32 -05:00
|
|
|
if stop {
|
|
|
|
break
|
|
|
|
}
|
2014-03-20 11:52:12 -04:00
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|