rootfs.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package image
  2. import (
  3. "runtime"
  4. "github.com/Sirupsen/logrus"
  5. "github.com/docker/docker/layer"
  6. )
  7. // TypeLayers is used for RootFS.Type for filesystems organized into layers.
  8. const TypeLayers = "layers"
  9. // typeLayersWithBase is an older format used by Windows up to v1.12. We
  10. // explicitly handle this as an error case to ensure that a daemon which still
  11. // has an older image like this on disk can still start, even though the
  12. // image itself is not usable. See https://github.com/docker/docker/pull/25806.
  13. const typeLayersWithBase = "layers+base"
  14. // RootFS describes images root filesystem
  15. // This is currently a placeholder that only supports layers. In the future
  16. // this can be made into an interface that supports different implementations.
  17. type RootFS struct {
  18. Type string `json:"type"`
  19. DiffIDs []layer.DiffID `json:"diff_ids,omitempty"`
  20. }
  21. // NewRootFS returns empty RootFS struct
  22. func NewRootFS() *RootFS {
  23. return &RootFS{Type: TypeLayers}
  24. }
  25. // Append appends a new diffID to rootfs
  26. func (r *RootFS) Append(id layer.DiffID) {
  27. r.DiffIDs = append(r.DiffIDs, id)
  28. }
  29. // ChainID returns the ChainID for the top layer in RootFS.
  30. func (r *RootFS) ChainID() layer.ChainID {
  31. if runtime.GOOS == "windows" && r.Type == typeLayersWithBase {
  32. logrus.Warnf("Layer type is unsupported on this platform. DiffIDs: '%v'", r.DiffIDs)
  33. return ""
  34. }
  35. return layer.CreateChainID(r.DiffIDs)
  36. }