getlayermountpath.go 1.5 KB

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