format.go 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. //go:build windows
  2. package computestorage
  3. import (
  4. "context"
  5. "github.com/Microsoft/hcsshim/internal/oc"
  6. "github.com/pkg/errors"
  7. "golang.org/x/sys/windows"
  8. )
  9. // FormatWritableLayerVhd formats a virtual disk for use as a writable container layer.
  10. //
  11. // If the VHD is not mounted it will be temporarily mounted.
  12. //
  13. // NOTE: This API had a breaking change in the operating system after Windows Server 2019.
  14. // On ws2019 the API expects to get passed a file handle from CreateFile for the vhd that
  15. // the caller wants to format. On > ws2019, its expected that the caller passes a vhd handle
  16. // that can be obtained from the virtdisk APIs.
  17. func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err error) {
  18. title := "hcsshim::FormatWritableLayerVhd"
  19. ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
  20. defer span.End()
  21. defer func() { oc.SetSpanStatus(span, err) }()
  22. err = hcsFormatWritableLayerVhd(vhdHandle)
  23. if err != nil {
  24. return errors.Wrap(err, "failed to format writable layer vhd")
  25. }
  26. return nil
  27. }