getlayermountpath.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package wclayer
  2. import (
  3. "syscall"
  4. "github.com/Microsoft/hcsshim/internal/hcserror"
  5. "github.com/sirupsen/logrus"
  6. )
  7. // GetLayerMountPath will look for a mounted layer with the given path and return
  8. // the path at which that layer can be accessed. This path may be a volume path
  9. // if the layer is a mounted read-write layer, otherwise it is expected to be the
  10. // folder path at which the layer is stored.
  11. func GetLayerMountPath(path string) (string, error) {
  12. title := "hcsshim::GetLayerMountPath "
  13. logrus.Debugf(title+"path %s", path)
  14. var mountPathLength uintptr
  15. mountPathLength = 0
  16. // Call the procedure itself.
  17. logrus.Debugf("Calling proc (1)")
  18. err := getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
  19. if err != nil {
  20. err = hcserror.Errorf(err, title, "(first call) path=%s", path)
  21. logrus.Error(err)
  22. return "", err
  23. }
  24. // Allocate a mount path of the returned length.
  25. if mountPathLength == 0 {
  26. return "", nil
  27. }
  28. mountPathp := make([]uint16, mountPathLength)
  29. mountPathp[0] = 0
  30. // Call the procedure again
  31. logrus.Debugf("Calling proc (2)")
  32. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
  33. if err != nil {
  34. err = hcserror.Errorf(err, title, "(second call) path=%s", path)
  35. logrus.Error(err)
  36. return "", err
  37. }
  38. mountPath := syscall.UTF16ToString(mountPathp[0:])
  39. logrus.Debugf(title+"succeeded path=%s mountPath=%s", path, mountPath)
  40. return mountPath, nil
  41. }