2018-09-05 14:54:38 -04:00
|
|
|
package wclayer
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
2018-03-19 18:57:30 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
// GetLayerMountPath will look for a mounted layer with the given path and return
|
2018-03-19 18:57:30 -04:00
|
|
|
// the path at which that layer can be accessed. This path may be a volume path
|
|
|
|
// if the layer is a mounted read-write layer, otherwise it is expected to be the
|
|
|
|
// folder path at which the layer is stored.
|
2018-09-05 14:54:38 -04:00
|
|
|
func GetLayerMountPath(path string) (string, error) {
|
2018-03-19 18:57:30 -04:00
|
|
|
title := "hcsshim::GetLayerMountPath "
|
2018-09-05 14:54:38 -04:00
|
|
|
logrus.Debugf(title+"path %s", path)
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
var mountPathLength uintptr
|
|
|
|
mountPathLength = 0
|
|
|
|
|
|
|
|
// Call the procedure itself.
|
|
|
|
logrus.Debugf("Calling proc (1)")
|
2018-09-05 14:54:38 -04:00
|
|
|
err := getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2018-09-05 14:54:38 -04:00
|
|
|
err = hcserror.Errorf(err, title, "(first call) path=%s", path)
|
2018-03-19 18:57:30 -04:00
|
|
|
logrus.Error(err)
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a mount path of the returned length.
|
|
|
|
if mountPathLength == 0 {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
mountPathp := make([]uint16, mountPathLength)
|
|
|
|
mountPathp[0] = 0
|
|
|
|
|
|
|
|
// Call the procedure again
|
|
|
|
logrus.Debugf("Calling proc (2)")
|
2018-09-05 14:54:38 -04:00
|
|
|
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2018-09-05 14:54:38 -04:00
|
|
|
err = hcserror.Errorf(err, title, "(second call) path=%s", path)
|
2018-03-19 18:57:30 -04:00
|
|
|
logrus.Error(err)
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
mountPath := syscall.UTF16ToString(mountPathp[0:])
|
|
|
|
logrus.Debugf(title+"succeeded path=%s mountPath=%s", path, mountPath)
|
|
|
|
return mountPath, nil
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|