2015-07-13 19:14:24 +05:00
|
|
|
// +build linux
|
|
|
|
|
2015-02-11 22:48:32 -08:00
|
|
|
package util
|
|
|
|
|
|
|
|
/*
|
2016-02-29 17:01:33 -08:00
|
|
|
#cgo LDFLAGS: -lmount -lblkid -luuid
|
2015-02-11 22:48:32 -08:00
|
|
|
#include<blkid/blkid.h>
|
2015-02-12 14:34:16 -08:00
|
|
|
#include<libmount/libmount.h>
|
2015-02-11 22:48:32 -08:00
|
|
|
#include<stdlib.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
|
2015-02-12 14:34:16 -08:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2015-02-11 22:48:32 -08:00
|
|
|
func ResolveDevice(spec string) string {
|
2015-02-12 14:34:16 -08:00
|
|
|
cSpec := C.CString(spec)
|
|
|
|
defer C.free(unsafe.Pointer(cSpec))
|
|
|
|
cString := C.blkid_evaluate_spec(cSpec, nil)
|
2015-02-16 22:09:26 -07:00
|
|
|
defer C.free(unsafe.Pointer(cString))
|
2015-02-11 22:48:32 -08:00
|
|
|
return C.GoString(cString)
|
|
|
|
}
|
|
|
|
|
2015-02-12 14:34:16 -08:00
|
|
|
func GetFsType(device string) (string, error) {
|
2015-02-16 22:09:26 -07:00
|
|
|
var ambi *C.int
|
2015-02-12 14:34:16 -08:00
|
|
|
cDevice := C.CString(device)
|
|
|
|
defer C.free(unsafe.Pointer(cDevice))
|
|
|
|
cString := C.mnt_get_fstype(cDevice, ambi, nil)
|
|
|
|
defer C.free(unsafe.Pointer(cString))
|
|
|
|
if cString != nil {
|
|
|
|
return C.GoString(cString), nil
|
2015-02-16 22:09:26 -07:00
|
|
|
}
|
2015-02-12 14:34:16 -08:00
|
|
|
return "", errors.New("Error while getting fstype")
|
|
|
|
}
|