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