cutil.go 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // +build linux
  2. package util
  3. /*
  4. #cgo LDFLAGS: -lmount -lblkid -luuid -lselinux
  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. }
  32. func intToBool(value C.int) bool {
  33. if value == 0 {
  34. return false
  35. }
  36. return true
  37. }