github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/image/rootfs.go (about) 1 package image // import "github.com/demonoid81/moby/image" 2 3 import ( 4 "runtime" 5 6 "github.com/demonoid81/moby/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/demonoid81/moby/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 = make([]layer.DiffID, len(r.DiffIDs)) 42 copy(newRoot.DiffIDs, r.DiffIDs) 43 return newRoot 44 } 45 46 // ChainID returns the ChainID for the top layer in RootFS. 47 func (r *RootFS) ChainID() layer.ChainID { 48 if runtime.GOOS == "windows" && r.Type == typeLayersWithBase { 49 logrus.Warnf("Layer type is unsupported on this platform. DiffIDs: '%v'", r.DiffIDs) 50 return "" 51 } 52 return layer.CreateChainID(r.DiffIDs) 53 }