cutil.go 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // ResolveDevice this isn't reliable - blkid -L LABEL works more often :(
  15. func ResolveDevice(spec string) string {
  16. cSpec := C.CString(spec)
  17. defer C.free(unsafe.Pointer(cSpec))
  18. cString := C.blkid_evaluate_spec(cSpec, nil)
  19. defer C.free(unsafe.Pointer(cString))
  20. return C.GoString(cString)
  21. }
  22. func GetFsType(device string) (string, error) {
  23. var ambi *C.int
  24. cDevice := C.CString(device)
  25. defer C.free(unsafe.Pointer(cDevice))
  26. cString := C.mnt_get_fstype(cDevice, ambi, nil)
  27. defer C.free(unsafe.Pointer(cString))
  28. if cString != nil {
  29. return C.GoString(cString), nil
  30. }
  31. return "", errors.New("Error while getting fstype")
  32. }