getlayermountpath.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //go:build windows
  2. package wclayer
  3. import (
  4. "context"
  5. "syscall"
  6. "github.com/Microsoft/hcsshim/internal/hcserror"
  7. "github.com/Microsoft/hcsshim/internal/log"
  8. "github.com/Microsoft/hcsshim/internal/oc"
  9. "go.opencensus.io/trace"
  10. )
  11. // GetLayerMountPath will look for a mounted layer with the given path and return
  12. // the path at which that layer can be accessed. This path may be a volume path
  13. // if the layer is a mounted read-write layer, otherwise it is expected to be the
  14. // folder path at which the layer is stored.
  15. func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
  16. title := "hcsshim::GetLayerMountPath"
  17. ctx, span := oc.StartSpan(ctx, title)
  18. defer span.End()
  19. defer func() { oc.SetSpanStatus(span, err) }()
  20. span.AddAttributes(trace.StringAttribute("path", path))
  21. var mountPathLength uintptr = 0
  22. // Call the procedure itself.
  23. log.G(ctx).Debug("Calling proc (1)")
  24. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
  25. if err != nil {
  26. return "", hcserror.New(err, title, "(first call)")
  27. }
  28. // Allocate a mount path of the returned length.
  29. if mountPathLength == 0 {
  30. return "", nil
  31. }
  32. mountPathp := make([]uint16, mountPathLength)
  33. mountPathp[0] = 0
  34. // Call the procedure again
  35. log.G(ctx).Debug("Calling proc (2)")
  36. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
  37. if err != nil {
  38. return "", hcserror.New(err, title, "(second call)")
  39. }
  40. mountPath := syscall.UTF16ToString(mountPathp[0:])
  41. span.AddAttributes(trace.StringAttribute("mountPath", mountPath))
  42. return mountPath, nil
  43. }