1
0
mirror of https://github.com/rancher/os.git synced 2025-09-16 06:59:12 +00:00

find fs type of device automatically

This commit is contained in:
sidharthamani
2015-02-12 14:34:16 -08:00
parent 34b3057909
commit 70b376ce6a
3 changed files with 53 additions and 9 deletions

View File

@@ -1,16 +1,41 @@
package util
/*
#cgo LDFLAGS: -lblkid -luuid
#cgo LDFLAGS: -lmount -lblkid -luuid
#include<blkid/blkid.h>
#include<libmount/libmount.h>
#include<stdlib.h>
*/
import "C"
import "unsafe"
import (
"errors"
)
func ResolveDevice(spec string) string {
cString := C.blkid_evaluate_spec(C.CString(spec), nil)
cSpec := C.CString(spec)
defer C.free(unsafe.Pointer(cSpec))
cString := C.blkid_evaluate_spec(cSpec, nil)
defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
}
func GetFsType(device string) (string, error) {
var ambi * C.int
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
}
return "", errors.New("Error while getting fstype")
}
func intToBool(value C.int) bool {
if value == 0 {
return false
}
return true
}