github.com/toplink-cn/moby@v0.0.0-20240305205811-460b4aebdf81/image/rootfs.go (about)

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