1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 14:23:11 +00:00
Files
os/util/cutil.go

42 lines
831 B
Go
Raw Normal View History

2015-02-11 22:48:32 -08:00
package util
/*
2015-02-16 22:09:26 -07:00
#cgo LDFLAGS: -lmount -lblkid -luuid -lselinux
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")
}
func intToBool(value C.int) bool {
if value == 0 {
return false
}
return true
}