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.
|
2019-02-28 13:16:30 -05:00
|
|
|
func GetLayerMountPath(path string) (_ string, err error) {
|
|
|
|
title := "hcsshim::GetLayerMountPath"
|
|
|
|
fields := logrus.Fields{
|
|
|
|
"path": path,
|
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Debug(title)
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
fields[logrus.ErrorKey] = err
|
|
|
|
logrus.WithFields(fields).Error(err)
|
|
|
|
} else {
|
|
|
|
logrus.WithFields(fields).Debug(title + " - succeeded")
|
|
|
|
}
|
|
|
|
}()
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
var mountPathLength uintptr
|
|
|
|
mountPathLength = 0
|
|
|
|
|
|
|
|
// Call the procedure itself.
|
2019-02-28 13:16:30 -05:00
|
|
|
logrus.WithFields(fields).Debug("Calling proc (1)")
|
|
|
|
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2019-02-28 13:16:30 -05:00
|
|
|
return "", hcserror.New(err, title+" - failed", "(first call)")
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a mount path of the returned length.
|
|
|
|
if mountPathLength == 0 {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
mountPathp := make([]uint16, mountPathLength)
|
|
|
|
mountPathp[0] = 0
|
|
|
|
|
|
|
|
// Call the procedure again
|
2019-02-28 13:16:30 -05:00
|
|
|
logrus.WithFields(fields).Debug("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 {
|
2019-02-28 13:16:30 -05:00
|
|
|
return "", hcserror.New(err, title+" - failed", "(second call)")
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
mountPath := syscall.UTF16ToString(mountPathp[0:])
|
2019-02-28 13:16:30 -05:00
|
|
|
fields["mountPath"] = mountPath
|
2018-09-05 14:54:38 -04:00
|
|
|
return mountPath, nil
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|