...

Source file src/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go

Documentation: github.com/Microsoft/hcsshim/internal/wclayer

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

View as plain text