mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Tobias Klauser](/assets/img/avatar_default.png)
Make sure to call C.free on C string allocated using C.CString in every exit path. C.CString allocates memory in the C heap using malloc. It is the callers responsibility to free them. See https://golang.org/cmd/cgo/#hdr-Go_references_to_C for details. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
44 lines
837 B
Go
44 lines
837 B
Go
// +build solaris,cgo
|
|
|
|
package mount
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mnttab.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
)
|
|
|
|
func parseMountTable() ([]*Info, error) {
|
|
path := C.CString(C.MNTTAB)
|
|
defer C.free(unsafe.Pointer(path))
|
|
mode := C.CString("r")
|
|
defer C.free(unsafe.Pointer(mode))
|
|
|
|
mnttab := C.fopen(path, mode)
|
|
if mnttab == nil {
|
|
return nil, fmt.Errorf("Failed to open %s", C.MNTTAB)
|
|
}
|
|
|
|
var out []*Info
|
|
var mp C.struct_mnttab
|
|
|
|
ret := C.getmntent(mnttab, &mp)
|
|
for ret == 0 {
|
|
var mountinfo Info
|
|
mountinfo.Mountpoint = C.GoString(mp.mnt_mountp)
|
|
mountinfo.Source = C.GoString(mp.mnt_special)
|
|
mountinfo.Fstype = C.GoString(mp.mnt_fstype)
|
|
mountinfo.Opts = C.GoString(mp.mnt_mntopts)
|
|
out = append(out, &mountinfo)
|
|
ret = C.getmntent(mnttab, &mp)
|
|
}
|
|
|
|
C.fclose(mnttab)
|
|
return out, nil
|
|
}
|