forked from microsoft/hcsshim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetsharedbaseimages.go
56 lines (45 loc) · 1.31 KB
/
getsharedbaseimages.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
package hcsshim
import (
"fmt"
"syscall"
"unsafe"
"github.com/Sirupsen/logrus"
)
// GetSharedBaseImages will enumerate the images stored in the common central
// image store and return descriptive info about those images for the purpose
// of registering them with the graphdriver, graph, and tagstore.
func GetSharedBaseImages() (imageData string, err error) {
title := "hcsshim::GetSharedBaseImages "
// Load the DLL and get a handle to the procedure we need
dll, proc, err := loadAndFind(procGetSharedBaseImages)
if dll != nil {
defer dll.Release()
}
if err != nil {
return
}
// Load the OLE DLL and get a handle to the CoTaskMemFree procedure
dll2, proc2, err := loadAndFindFromDll(oleDLLName, procCoTaskMemFree)
if dll2 != nil {
defer dll2.Release()
}
if err != nil {
return
}
var output uintptr
// Call the procedure again
logrus.Debugf("Calling proc")
r1, _, _ := proc.Call(
uintptr(unsafe.Pointer(&output)))
if r1 != 0 {
err = fmt.Errorf(title+" - Win32 API call returned error r1=%d errno=%s",
r1, syscall.Errno(r1))
logrus.Error(err)
return
}
// Defer the cleanup of the memory using CoTaskMemFree
defer proc2.Call(output)
imageData = syscall.UTF16ToString((*[1 << 30]uint16)(unsafe.Pointer(output))[:])
logrus.Debugf(title+" - succeeded output=%s", imageData)
return
}