forked from hyperhq/hyperd
/
createlayer.go
69 lines (58 loc) · 1.77 KB
/
createlayer.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
package hcsshim
import (
"fmt"
"syscall"
"unsafe"
"github.com/Sirupsen/logrus"
)
// CreateLayer creates a new, empty, read-only layer on the filesystem based on
// the parent layer provided.
func CreateLayer(info DriverInfo, id, parent string) error {
title := "hcsshim::CreateLayer "
logrus.Debugf(title+"Flavour %d ID %s parent %s", info.Flavour, id, parent)
// Load the DLL and get a handle to the procedure we need
dll, proc, err := loadAndFind(procCreateLayer)
if dll != nil {
defer dll.Release()
}
if err != nil {
return err
}
// Convert id to uint16 pointer for calling the procedure
idp, err := syscall.UTF16PtrFromString(id)
if err != nil {
err = fmt.Errorf(title+" - Failed conversion of id %s to pointer %s", id, err)
logrus.Error(err)
return err
}
// Convert parent to uint16 pointer for calling the procedure
parentp, err := syscall.UTF16PtrFromString(parent)
if err != nil {
err = fmt.Errorf(title+" - Failed conversion of parent %s to pointer %s", parent, 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", parent, err)
logrus.Error(err)
return err
}
// Call the procedure itself.
r1, _, _ := proc.Call(
uintptr(unsafe.Pointer(&infop)),
uintptr(unsafe.Pointer(idp)),
uintptr(unsafe.Pointer(parentp)))
use(unsafe.Pointer(&infop))
use(unsafe.Pointer(idp))
use(unsafe.Pointer(parentp))
if r1 != 0 {
err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s parent=%s flavour=%d",
r1, syscall.Errno(r1), id, parent, info.Flavour)
logrus.Error(err)
return err
}
logrus.Debugf(title+" - succeeded id=%s parent=%s flavour=%d", id, parent, info.Flavour)
return nil
}