1package hcsshim
2
3import (
4	"syscall"
5
6	"github.com/sirupsen/logrus"
7)
8
9// GetLayerMountPath will look for a mounted layer with the given id and return
10// the path at which that layer can be accessed.  This path may be a volume path
11// if the layer is a mounted read-write layer, otherwise it is expected to be the
12// folder path at which the layer is stored.
13func GetLayerMountPath(info DriverInfo, id string) (string, error) {
14	title := "hcsshim::GetLayerMountPath "
15	logrus.Debugf(title+"Flavour %d ID %s", info.Flavour, id)
16
17	// Convert info to API calling convention
18	infop, err := convertDriverInfo(info)
19	if err != nil {
20		logrus.Error(err)
21		return "", err
22	}
23
24	var mountPathLength uintptr
25	mountPathLength = 0
26
27	// Call the procedure itself.
28	logrus.Debugf("Calling proc (1)")
29	err = getLayerMountPath(&infop, id, &mountPathLength, nil)
30	if err != nil {
31		err = makeErrorf(err, title, "(first call) id=%s flavour=%d", id, info.Flavour)
32		logrus.Error(err)
33		return "", err
34	}
35
36	// Allocate a mount path of the returned length.
37	if mountPathLength == 0 {
38		return "", nil
39	}
40	mountPathp := make([]uint16, mountPathLength)
41	mountPathp[0] = 0
42
43	// Call the procedure again
44	logrus.Debugf("Calling proc (2)")
45	err = getLayerMountPath(&infop, id, &mountPathLength, &mountPathp[0])
46	if err != nil {
47		err = makeErrorf(err, title, "(second call) id=%s flavour=%d", id, info.Flavour)
48		logrus.Error(err)
49		return "", err
50	}
51
52	path := syscall.UTF16ToString(mountPathp[0:])
53	logrus.Debugf(title+"succeeded flavour=%d id=%s path=%s", info.Flavour, id, path)
54	return path, nil
55}
56