driver_solaris.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // +build solaris,cgo
  2. package graphdriver
  3. /*
  4. #include <sys/statvfs.h>
  5. #include <stdlib.h>
  6. static inline struct statvfs *getstatfs(char *s) {
  7. struct statvfs *buf;
  8. int err;
  9. buf = (struct statvfs *)malloc(sizeof(struct statvfs));
  10. err = statvfs(s, buf);
  11. return buf;
  12. }
  13. */
  14. import "C"
  15. import (
  16. "path/filepath"
  17. "unsafe"
  18. "github.com/Sirupsen/logrus"
  19. )
  20. const (
  21. // FsMagicZfs filesystem id for Zfs
  22. FsMagicZfs = FsMagic(0x2fc12fc1)
  23. )
  24. var (
  25. // Slice of drivers that should be used in an order
  26. priority = []string{
  27. "zfs",
  28. }
  29. // FsNames maps filesystem id to name of the filesystem.
  30. FsNames = map[FsMagic]string{
  31. FsMagicZfs: "zfs",
  32. }
  33. )
  34. // GetFSMagic returns the filesystem id given the path.
  35. func GetFSMagic(rootpath string) (FsMagic, error) {
  36. return 0, nil
  37. }
  38. // Mounted checks if the given path is mounted as the fs type
  39. //Solaris supports only ZFS for now
  40. func Mounted(fsType FsMagic, mountPath string) (bool, error) {
  41. cs := C.CString(filepath.Dir(mountPath))
  42. buf := C.getstatfs(cs)
  43. // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
  44. if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
  45. (buf.f_basetype[3] != 0) {
  46. logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
  47. C.free(unsafe.Pointer(buf))
  48. return false, ErrPrerequisites
  49. }
  50. C.free(unsafe.Pointer(buf))
  51. C.free(unsafe.Pointer(cs))
  52. return true, nil
  53. }