image

package
v4.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package image provides underlying data types for Singularity image formats. Additionally, all image types will satisfy the ImageFormat{} interface. This interface will expose all things necessary to use a Singularity image, whether through OCI or directly.

type ImageFormat interface {
    Root() *spec.Root - Root() returns the OCI compliant root of the
                        Image. This function may perform some action,
                        such as extracting the filesystem to a dir.
}

Index

Constants

View Source
const (
	// SQUASHFS constant for squashfs format
	SQUASHFS = iota + 0x1000
	// EXT3 constant for ext3 format
	EXT3
	// SANDBOX constant for directory format
	SANDBOX
	// SIF constant for sif format (native image, not OCI-SIF)
	SIF
	// ENCRYPTSQUASHFS constant for encrypted squashfs format
	ENCRYPTSQUASHFS
	// RAW constant for raw format
	RAW
	// OCISIF constant for OCI-SIF images
	OCISIF
)
View Source
const (
	// RootFsUsage defines flag for image/partition
	// usable as root filesystem.
	RootFsUsage = Usage(1 << iota)
	// OverlayUsage defines flag for image/partition
	// usable as overlay.
	OverlayUsage
	// DataUsage defines flag for image/partition
	// usable as data.
	DataUsage
)
View Source
const (
	// ErrNoSection corresponds to an image section not found.
	ErrNoSection = readerError("no section found")
	// ErrNoPartition corresponds to an image partition not found.
	ErrNoPartition = readerError("no partition found")
)
View Source
const (
	// SIFDescOCIConfigJSON is the name of the SIF descriptor holding the OCI configuration.
	SIFDescOCIConfigJSON = "oci-config.json"
	// SIFDescInspectMetadataJSON is the name of the SIF descriptor holding the container metadata.
	SIFDescInspectMetadataJSON = "inspect-metadata.json"
)
View Source
const (
	// RootFs partition name
	RootFs = "!__rootfs__!"
)

Variables

View Source
var ErrUnknownFormat = errors.New("image format not recognized")

ErrUnknownFormat represents an unknown image format error.

Functions

func CheckExt3Header

func CheckExt3Header(b []byte) (uint64, error)

CheckExt3Header checks if byte content contains a valid ext3 header and returns offset where ext3 partition begin

func CheckSquashfsHeader

func CheckSquashfsHeader(b []byte) (uint64, error)

CheckSquashfsHeader checks if byte content contains a valid squashfs header and returns offset where squashfs partition starts

func GetSquashfsComp

func GetSquashfsComp(b []byte) (string, error)

GetSquashfsComp checks if byte content contains a valid squashfs header and returns type of compression used

func IsOCISIF added in v4.1.0

func IsOCISIF(filename string) (bool, error)

IsOCISIF receives a path to an image file and returns a boolean indicating whether the file is an OCI-SIF image.

func IsReadOnlyFilesytem

func IsReadOnlyFilesytem(err error) bool

IsReadOnlyFilesytem returns if the corresponding error is a read-only filesystem error or not.

func NewPartitionReader

func NewPartitionReader(image *Image, name string, index int) (io.Reader, error)

NewPartitionReader searches and returns a reader for an image partition identified by name or by index, if index is less than 0 only partition with provided name will be returned if a matching entry is found

func NewSectionReader

func NewSectionReader(image *Image, name string, index int) (io.Reader, error)

NewSectionReader searches and returns a reader for an image section identified by name or by index, if index is less than 0 only section with provided name will be returned if a matching entry is found.

func ResolvePath

func ResolvePath(path string) (string, error)

ResolvePath returns a resolved absolute path.

Types

type Image

type Image struct {
	Partitions []Section `json:"partitions"`
	Sections   []Section `json:"sections"`
	Path       string    `json:"path"`
	Name       string    `json:"name"`
	Source     string    `json:"source"`
	Type       int       `json:"type"`
	File       *os.File  `json:"-"`
	Fd         uintptr   `json:"fd"`
	Writable   bool      `json:"writable"`
	Usage      Usage     `json:"usage"`
}

Image describes an image object, an image is composed of one or more partitions (eg: container root filesystem, overlay), image format like SIF contains descriptors pointing to chunk of data, chunks position and size are stored as image sections.

func Init

func Init(path string, writable bool) (*Image, error)

Init initializes an image object based on given path.

func (*Image) AuthorizedGroup

func (i *Image) AuthorizedGroup(groups []string) (bool, error)

AuthorizedGroup checks whether the image is owned by any group from the supplied groups list.

func (*Image) AuthorizedOwner

func (i *Image) AuthorizedOwner(owners []string) (bool, error)

AuthorizedOwner checks whether the image is owned by any user from the supplied users list.

func (*Image) AuthorizedPath

func (i *Image) AuthorizedPath(paths []string) (bool, error)

AuthorizedPath checks if image is in a path supplied in paths

func (*Image) GetAllPartitions

func (i *Image) GetAllPartitions() ([]Section, error)

GetAllPartitions returns all partitions found in the image.

func (*Image) GetDataPartitions

func (i *Image) GetDataPartitions() ([]Section, error)

GetDataPartitions returns data partitions found in the image.

func (*Image) GetOverlayPartitions

func (i *Image) GetOverlayPartitions() ([]Section, error)

GetOverlayPartitions returns overlay partitions found in the image.

func (*Image) GetRootFsPartition

func (i *Image) GetRootFsPartition() (*Section, error)

GetRootFsPartition returns the first root filesystem partition found in the image.

func (*Image) GetRootFsPartitions

func (i *Image) GetRootFsPartitions() ([]Section, error)

GetRootFsPartitions returns root filesystem partitions found in the image.

func (*Image) HasEncryptedRootFs

func (i *Image) HasEncryptedRootFs() (encrypted bool, err error)

HasEncryptedRootFs returns true if the image contains an encrypted rootfs partition.

type Section

type Section struct {
	Name         string `json:"name"`
	Size         uint64 `json:"size"`
	Offset       uint64 `json:"offset"`
	ID           uint32 `json:"id"`
	Type         uint32 `json:"type"`
	AllowedUsage Usage  `json:"allowed_usage"`
	// Architecture is only known for system partitions in SIF files.
	Architecture string `json:"architecture,omitempty"`
}

Section identifies and locates a data section in image object.

type Usage

type Usage uint8

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL