forked from microsoft/hcsshim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportlayer.go
88 lines (76 loc) · 2.63 KB
/
exportlayer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package hcsshim
import (
"fmt"
"syscall"
"unsafe"
"github.com/Sirupsen/logrus"
)
// ExportLayer will create a folder at exportFolderPath and fill that folder with
// the transport format version of the layer identified by layerId. This transport
// format includes any metadata required for later importing the layer (using
// ImportLayer), and requires the full list of parent layer paths in order to
// perform the export.
func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
title := "hcsshim::ExportLayer "
logrus.Debugf(title+"flavour %d layerId %s folder %s", info.Flavour, layerId, exportFolderPath)
// Load the DLL and get a handle to the procedure we need
dll, proc, err := loadAndFind(procExportLayer)
if dll != nil {
defer dll.Release()
}
if err != nil {
return err
}
// Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths)
if err != nil {
err = fmt.Errorf(title+"- Failed to generate layer descriptors ", err)
return err
}
// Convert layerId to uint16 pointer for calling the procedure
layerIdp, err := syscall.UTF16PtrFromString(layerId)
if err != nil {
err = fmt.Errorf(title+"- Failed conversion of layerId %s to pointer %s", layerId, err)
logrus.Error(err)
return err
}
// Convert exportFolderPath to uint16 pointer for calling the procedure
exportFolderPathp, err := syscall.UTF16PtrFromString(exportFolderPath)
if err != nil {
err = fmt.Errorf(title+"- Failed conversion of exportFolderPath %s to pointer %s", exportFolderPath, err)
logrus.Error(err)
return err
}
// Convert info to API calling convention
infop, err := convertDriverInfo(info)
if err != nil {
err = fmt.Errorf(title+"- Failed conversion info struct %s", err)
logrus.Error(err)
return err
}
var layerDescriptorsp *WC_LAYER_DESCRIPTOR
if len(layers) > 0 {
layerDescriptorsp = &(layers[0])
} else {
layerDescriptorsp = nil
}
// Call the procedure itself.
r1, _, _ := proc.Call(
uintptr(unsafe.Pointer(&infop)),
uintptr(unsafe.Pointer(layerIdp)),
uintptr(unsafe.Pointer(exportFolderPathp)),
uintptr(unsafe.Pointer(layerDescriptorsp)),
uintptr(len(layers)))
use(unsafe.Pointer(&infop))
use(unsafe.Pointer(layerIdp))
use(unsafe.Pointer(exportFolderPathp))
use(unsafe.Pointer(layerDescriptorsp))
if r1 != 0 {
err = fmt.Errorf(title+"- Win32 API call returned error r1=%d err=%s layerId=%s flavour=%d folder=%s",
r1, syscall.Errno(r1), layerId, info.Flavour, exportFolderPath)
logrus.Error(err)
return err
}
logrus.Debugf(title+"succeeded flavour=%d layerId=%s folder=%s", info.Flavour, layerId, exportFolderPath)
return nil
}