layerutils.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.Debugf("Failed to convert name to guid %s", err)
  62. return nil, err
  63. }
  64. p, err := syscall.UTF16PtrFromString(parentLayerPaths[i])
  65. if err != nil {
  66. logrus.Debugf("Failed conversion of parentLayerPath to pointer %s", err)
  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. }