cutil.go 752 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build linux
  2. package util
  3. /*
  4. #cgo LDFLAGS: -lmount -lblkid -luuid
  5. #include<blkid/blkid.h>
  6. #include<libmount/libmount.h>
  7. #include<stdlib.h>
  8. */
  9. import "C"
  10. import "unsafe"
  11. import (
  12. "errors"
  13. )
  14. func ResolveDevice(spec string) string {
  15. cSpec := C.CString(spec)
  16. defer C.free(unsafe.Pointer(cSpec))
  17. cString := C.blkid_evaluate_spec(cSpec, nil)
  18. defer C.free(unsafe.Pointer(cString))
  19. return C.GoString(cString)
  20. }
  21. func GetFsType(device string) (string, error) {
  22. var ambi *C.int
  23. cDevice := C.CString(device)
  24. defer C.free(unsafe.Pointer(cDevice))
  25. cString := C.mnt_get_fstype(cDevice, ambi, nil)
  26. defer C.free(unsafe.Pointer(cString))
  27. if cString != nil {
  28. return C.GoString(cString), nil
  29. }
  30. return "", errors.New("Error while getting fstype")
  31. }