layer.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //go:build windows
  2. package hcsshim
  3. import (
  4. "context"
  5. "crypto/sha1"
  6. "path/filepath"
  7. "github.com/Microsoft/go-winio/pkg/guid"
  8. "github.com/Microsoft/hcsshim/internal/wclayer"
  9. )
  10. func layerPath(info *DriverInfo, id string) string {
  11. return filepath.Join(info.HomeDir, id)
  12. }
  13. func ActivateLayer(info DriverInfo, id string) error {
  14. return wclayer.ActivateLayer(context.Background(), layerPath(&info, id))
  15. }
  16. func CreateLayer(info DriverInfo, id, parent string) error {
  17. return wclayer.CreateLayer(context.Background(), layerPath(&info, id), parent)
  18. }
  19. // New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility.
  20. func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
  21. return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
  22. }
  23. func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
  24. return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
  25. }
  26. func DeactivateLayer(info DriverInfo, id string) error {
  27. return wclayer.DeactivateLayer(context.Background(), layerPath(&info, id))
  28. }
  29. func DestroyLayer(info DriverInfo, id string) error {
  30. return wclayer.DestroyLayer(context.Background(), layerPath(&info, id))
  31. }
  32. // New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility.
  33. func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
  34. return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
  35. }
  36. func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error {
  37. return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
  38. }
  39. func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
  40. return wclayer.ExportLayer(context.Background(), layerPath(&info, layerId), exportFolderPath, parentLayerPaths)
  41. }
  42. func GetLayerMountPath(info DriverInfo, id string) (string, error) {
  43. return wclayer.GetLayerMountPath(context.Background(), layerPath(&info, id))
  44. }
  45. func GetSharedBaseImages() (imageData string, err error) {
  46. return wclayer.GetSharedBaseImages(context.Background())
  47. }
  48. func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error {
  49. return wclayer.ImportLayer(context.Background(), layerPath(&info, layerID), importFolderPath, parentLayerPaths)
  50. }
  51. func LayerExists(info DriverInfo, id string) (bool, error) {
  52. return wclayer.LayerExists(context.Background(), layerPath(&info, id))
  53. }
  54. func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
  55. return wclayer.PrepareLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
  56. }
  57. func ProcessBaseLayer(path string) error {
  58. return wclayer.ProcessBaseLayer(context.Background(), path)
  59. }
  60. func ProcessUtilityVMImage(path string) error {
  61. return wclayer.ProcessUtilityVMImage(context.Background(), path)
  62. }
  63. func UnprepareLayer(info DriverInfo, layerId string) error {
  64. return wclayer.UnprepareLayer(context.Background(), layerPath(&info, layerId))
  65. }
  66. func ConvertToBaseLayer(path string) error {
  67. return wclayer.ConvertToBaseLayer(context.Background(), path)
  68. }
  69. type DriverInfo struct {
  70. Flavour int
  71. HomeDir string
  72. }
  73. type GUID [16]byte
  74. func NameToGuid(name string) (id GUID, err error) {
  75. g, err := wclayer.NameToGuid(context.Background(), name)
  76. return g.ToWindowsArray(), err
  77. }
  78. func NewGUID(source string) *GUID {
  79. h := sha1.Sum([]byte(source))
  80. var g GUID
  81. copy(g[0:], h[0:16])
  82. return &g
  83. }
  84. func (g *GUID) ToString() string {
  85. return guid.FromWindowsArray(*g).String()
  86. }
  87. type LayerReader = wclayer.LayerReader
  88. func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
  89. return wclayer.NewLayerReader(context.Background(), layerPath(&info, layerID), parentLayerPaths)
  90. }
  91. type LayerWriter = wclayer.LayerWriter
  92. func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
  93. return wclayer.NewLayerWriter(context.Background(), layerPath(&info, layerID), parentLayerPaths)
  94. }
  95. type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR