2018-09-05 14:54:38 -04:00
|
|
|
package wclayer
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
// This file contains utility functions to support storage (graph) related
|
|
|
|
// functionality.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/guid"
|
2018-03-19 18:57:30 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* To pass into syscall, we need a struct matching the following:
|
|
|
|
enum GraphDriverType
|
|
|
|
{
|
|
|
|
DiffDriver,
|
|
|
|
FilterDriver
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DriverInfo {
|
|
|
|
GraphDriverType Flavour;
|
|
|
|
LPCWSTR HomeDir;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
type driverInfo struct {
|
|
|
|
Flavour int
|
|
|
|
HomeDirp *uint16
|
|
|
|
}
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
var (
|
|
|
|
utf16EmptyString uint16
|
|
|
|
stdDriverInfo = driverInfo{1, &utf16EmptyString}
|
|
|
|
)
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
/* To pass into syscall, we need a struct matching the following:
|
|
|
|
typedef struct _WC_LAYER_DESCRIPTOR {
|
|
|
|
|
|
|
|
//
|
|
|
|
// The ID of the layer
|
|
|
|
//
|
|
|
|
|
|
|
|
GUID LayerId;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Additional flags
|
|
|
|
//
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ULONG Reserved : 31;
|
|
|
|
ULONG Dirty : 1; // Created from sandbox as a result of snapshot
|
|
|
|
};
|
|
|
|
ULONG Value;
|
|
|
|
} Flags;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Path to the layer root directory, null-terminated
|
|
|
|
//
|
|
|
|
|
|
|
|
PCWSTR Path;
|
|
|
|
|
|
|
|
} WC_LAYER_DESCRIPTOR, *PWC_LAYER_DESCRIPTOR;
|
|
|
|
*/
|
|
|
|
type WC_LAYER_DESCRIPTOR struct {
|
2018-09-05 14:54:38 -04:00
|
|
|
LayerId guid.GUID
|
2018-03-19 18:57:30 -04:00
|
|
|
Flags uint32
|
|
|
|
Pathp *uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR, error) {
|
|
|
|
// Array of descriptors that gets constructed.
|
|
|
|
var layers []WC_LAYER_DESCRIPTOR
|
|
|
|
|
|
|
|
for i := 0; i < len(parentLayerPaths); i++ {
|
2018-09-05 14:54:38 -04:00
|
|
|
g, err := LayerID(parentLayerPaths[i])
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2019-02-28 13:16:30 -05:00
|
|
|
logrus.WithError(err).Debug("Failed to convert name to guid")
|
2018-03-19 18:57:30 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err := syscall.UTF16PtrFromString(parentLayerPaths[i])
|
|
|
|
if err != nil {
|
2019-02-28 13:16:30 -05:00
|
|
|
logrus.WithError(err).Debug("Failed conversion of parentLayerPath to pointer")
|
2018-03-19 18:57:30 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
layers = append(layers, WC_LAYER_DESCRIPTOR{
|
|
|
|
LayerId: g,
|
|
|
|
Flags: 0,
|
|
|
|
Pathp: p,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return layers, nil
|
|
|
|
}
|