layerutils.go 1.8 KB

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