...

Source file src/github.com/Microsoft/hcsshim/internal/wclayer/layerutils.go

Documentation: github.com/Microsoft/hcsshim/internal/wclayer

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

View as plain text