layerutils.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package wclayer
  2. // This file contains utility functions to support storage (graph) related
  3. // functionality.
  4. import (
  5. "syscall"
  6. "github.com/Microsoft/hcsshim/internal/guid"
  7. "github.com/sirupsen/logrus"
  8. )
  9. /* To pass into syscall, we need a struct matching the following:
  10. enum GraphDriverType
  11. {
  12. DiffDriver,
  13. FilterDriver
  14. };
  15. struct DriverInfo {
  16. GraphDriverType Flavour;
  17. LPCWSTR HomeDir;
  18. };
  19. */
  20. type driverInfo struct {
  21. Flavour int
  22. HomeDirp *uint16
  23. }
  24. var (
  25. utf16EmptyString uint16
  26. stdDriverInfo = driverInfo{1, &utf16EmptyString}
  27. )
  28. /* To pass into syscall, we need a struct matching the following:
  29. typedef struct _WC_LAYER_DESCRIPTOR {
  30. //
  31. // The ID of the layer
  32. //
  33. GUID LayerId;
  34. //
  35. // Additional flags
  36. //
  37. union {
  38. struct {
  39. ULONG Reserved : 31;
  40. ULONG Dirty : 1; // Created from sandbox as a result of snapshot
  41. };
  42. ULONG Value;
  43. } Flags;
  44. //
  45. // Path to the layer root directory, null-terminated
  46. //
  47. PCWSTR Path;
  48. } WC_LAYER_DESCRIPTOR, *PWC_LAYER_DESCRIPTOR;
  49. */
  50. type WC_LAYER_DESCRIPTOR struct {
  51. LayerId guid.GUID
  52. Flags uint32
  53. Pathp *uint16
  54. }
  55. func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR, error) {
  56. // Array of descriptors that gets constructed.
  57. var layers []WC_LAYER_DESCRIPTOR
  58. for i := 0; i < len(parentLayerPaths); i++ {
  59. g, err := LayerID(parentLayerPaths[i])
  60. if err != nil {
  61. logrus.WithError(err).Debug("Failed to convert name to guid")
  62. return nil, err
  63. }
  64. p, err := syscall.UTF16PtrFromString(parentLayerPaths[i])
  65. if err != nil {
  66. logrus.WithError(err).Debug("Failed conversion of parentLayerPath to pointer")
  67. return nil, err
  68. }
  69. layers = append(layers, WC_LAYER_DESCRIPTOR{
  70. LayerId: g,
  71. Flags: 0,
  72. Pathp: p,
  73. })
  74. }
  75. return layers, nil
  76. }