getlayermountpath.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, err error) {
  12. title := "hcsshim::GetLayerMountPath"
  13. fields := logrus.Fields{
  14. "path": path,
  15. }
  16. logrus.WithFields(fields).Debug(title)
  17. defer func() {
  18. if err != nil {
  19. fields[logrus.ErrorKey] = err
  20. logrus.WithFields(fields).Error(err)
  21. } else {
  22. logrus.WithFields(fields).Debug(title + " - succeeded")
  23. }
  24. }()
  25. var mountPathLength uintptr
  26. mountPathLength = 0
  27. // Call the procedure itself.
  28. logrus.WithFields(fields).Debug("Calling proc (1)")
  29. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
  30. if err != nil {
  31. return "", hcserror.New(err, title+" - failed", "(first call)")
  32. }
  33. // Allocate a mount path of the returned length.
  34. if mountPathLength == 0 {
  35. return "", nil
  36. }
  37. mountPathp := make([]uint16, mountPathLength)
  38. mountPathp[0] = 0
  39. // Call the procedure again
  40. logrus.WithFields(fields).Debug("Calling proc (2)")
  41. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
  42. if err != nil {
  43. return "", hcserror.New(err, title+" - failed", "(second call)")
  44. }
  45. mountPath := syscall.UTF16ToString(mountPathp[0:])
  46. fields["mountPath"] = mountPath
  47. return mountPath, nil
  48. }