2015-05-27 16:15:14 -04:00
|
|
|
package hcsshim
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2015-08-27 18:46:00 -04:00
|
|
|
// CreateLayer creates a new, empty, read-only layer on the filesystem based on
|
|
|
|
// the parent layer provided.
|
2015-05-27 16:15:14 -04:00
|
|
|
func CreateLayer(info DriverInfo, id, parent string) error {
|
|
|
|
title := "hcsshim::CreateLayer "
|
2015-10-12 19:34:03 -04:00
|
|
|
logrus.Debugf(title+"Flavour %d ID %s parent %s", info.Flavour, id, parent)
|
2015-05-27 16:15:14 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|