Documentation
¶
Index ¶
- Variables
- func AllocateOverlay(ctx context.Context, path string, sizeMB int)
- func Cat(sqfPath, filePath string) []byte
- func CheckAvailable(path string, write bool) error
- func CheckIntegrity(ctx context.Context, path string, force bool) error
- func ChownRecursively(ctx context.Context, imagePath string, uid, gid int, internalPath string) error
- func CreateDirectly(ctx context.Context, opts *CreateOptions) error
- func CreateInTmp(ctx context.Context, opts *CreateOptions) (tmpPath string, err error)
- func CreateWithOptions(ctx context.Context, opts *CreateOptions) error
- func GetOverlayType(sqfPath string) string
- func HasCntBin(sqfPath, nameVersion string) bool
- func IsOSType(sqfPath string) bool
- func ListCondaPackages(imgPath string) (map[string]string, error)
- func MoveOverlayCopied(ctx context.Context, src, dst string, sparse bool) (copied bool, err error)
- func PathExists(overlayPath, entry string) bool
- func ReadFile(overlayPath, innerPath string) []byte
- func Resize(ctx context.Context, imagePath string, newSizeMB int) error
- type CondaInfo
- type CreateOptions
- type Error
- type Lock
- type OSInfo
- type Profile
- type SquashFSStats
- type Stats
- type UIDStatus
Constants ¶
This section is empty.
Variables ¶
var ( // ProfileSmall is tuned for environments with many small files (Conda packages, Python/site-packages). ProfileSmall = Profile{InodeRatio: 4096, ReservedPerc: 3} // ProfileDefault is a general-purpose profile (Linux default 16K). ProfileDefault = Profile{InodeRatio: 16384, ReservedPerc: 3} // ProfileLarge is optimized for large files (genomes, FASTA, databases). ProfileLarge = Profile{InodeRatio: 1048576, ReservedPerc: 3} )
Functions ¶
func AllocateOverlay ¶ added in v1.3.0
AllocateOverlay pre-allocates disk blocks for a sparse overlay file using fallocate.
func Cat ¶ added in v1.2.0
Cat reads a file from a SquashFS archive using unsquashfs -cat. Returns nil if the file cannot be read.
func CheckAvailable ¶
CheckAvailable checks if the overlay image is available for reading or writing.
func CheckIntegrity ¶
CheckIntegrity runs a filesystem check (e2fsck) on the overlay image. force: If true, adds '-f' to force the check even if the filesystem appears clean. Returns an error immediately if the image is currently in use (mounted writable).
func ChownRecursively ¶
func ChownRecursively(ctx context.Context, imagePath string, uid, gid int, internalPath string) error
ChownRecursively changes the UID/GID of files inside an unmounted overlay image. It maps the provided internalPath (e.g., "/") to the overlay's "/upper" structure.
func CreateDirectly ¶ added in v1.3.0
func CreateDirectly(ctx context.Context, opts *CreateOptions) error
CreateDirectly builds the overlay at opts.Path without using a local tmp directory.
func CreateInTmp ¶ added in v1.3.0
func CreateInTmp(ctx context.Context, opts *CreateOptions) (tmpPath string, err error)
CreateInTmp builds the overlay at a local temp path and returns that path. The overlay is always created sparse to minimize local disk usage. The caller is responsible for running additional init, moving to final destination, and calling AllocateOverlay if needed. The caller must remove the temp file on error.
func CreateWithOptions ¶
func CreateWithOptions(ctx context.Context, opts *CreateOptions) error
CreateWithOptions builds the overlay at a local tmp path and moves it to opts.Path. If opts.Sparse is false, AllocateOverlay is called after the move to fill sparse holes. For cases where additional work must happen before the final move (e.g. conda init), use CreateInTmp + MoveOverlayCopied + AllocateOverlay instead.
func GetOverlayType ¶ added in v1.2.0
GetOverlayType classifies a SquashFS overlay based on its contents and filename:
- "OS Overlay" : contains .singularity.d (Apptainer-built)
- "Module Overlay" : contains cnt/ and filename uses -- name/version separator
- "Bundle Overlay" : contains cnt/ but filename has no --
- "" : unrecognized
func HasCntBin ¶ added in v1.2.0
HasCntBin returns true if the SquashFS archive contains a bin directory at cnt/<name>/<version>/bin. nameVersion accepts both slash form ("samtools/1.22") and the normalized double-dash form ("samtools--1.22").
func IsOSType ¶ added in v1.2.0
IsOSType returns true if the SquashFS archive is an Apptainer OS image, identified by the presence of .singularity.d at the archive root.
func ListCondaPackages ¶ added in v1.5.0
ListCondaPackages reads the conda-meta directory from a writable ext3 overlay image and returns a map of package name → installed version for every conda package found. The conda environment is expected at /ext3/env inside the container, which maps to upper/ext3/env/conda-meta inside the .img file.
Returns (nil, nil) for non-.img files or when no conda-meta directory exists.
func MoveOverlayCopied ¶ added in v1.3.0
MoveOverlayCopied moves src to dst and reports whether a copy was performed.
func PathExists ¶ added in v1.2.0
PathExists dispatches to the appropriate backend check depending on the overlay type.
Types ¶
type CondaInfo ¶ added in v1.4.1
CondaInfo holds the channels and explicitly-requested packages parsed from a conda-meta/history file inside an overlay.
func ReadCondaInfo ¶ added in v1.4.1
ReadCondaInfo reads conda-meta/history from envPrefix inside the overlay and returns the channels and explicitly-installed package specs. Returns nil if the history file is absent or contains no specs.
type CreateOptions ¶
type CreateOptions struct {
Path string // Path to the overlay image file
SizeMB int // Size in megabytes
UID int // Owner user ID
GID int // Owner group ID
Profile Profile // Filesystem tuning profile
Sparse bool // Create sparse file (vs allocated)
FilesystemType string // Filesystem type: "ext3" or "ext4" (default: "ext3")
Quiet bool // Suppress detailed specs output
}
CreateOptions holds all configuration options for creating an overlay image.
type Error ¶
type Error struct {
Op string // high level intent: "create", "resize"
Tool string // low level tool: "mke2fs", "dd", "debugfs"
Path string // the file being manipulated
Output string // Captured Stderr/Stdout
BaseErr error // The underlying execution error
}
Error represents a failure in filesystem tools (dd, mkfs, debugfs, etc.). Usage: if err, ok := err.(*overlay.Error); ok { ... }
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents a file lock on an overlay image. It must be closed to release the lock.
func AcquireLock ¶
AcquireLock attempts to acquire a lock on the overlay file. If write is true, it attempts an exclusive lock (LOCK_EX). If write is false, it attempts a shared lock (LOCK_SH). Both are non-blocking (LOCK_NB).
type OSInfo ¶ added in v1.2.0
type OSInfo struct {
ID string // e.g. "ubuntu", "debian", "rhel", "rocky"
IDLike []string // e.g. ["debian"] for ubuntu, ["rhel", "fedora"] for rocky/alma
VersionID string // e.g. "24.04", "12", "9.3"
Codename string // e.g. "Noble", "Bookworm", "Blue Onyx" (title-cased)
Name string // e.g. "Ubuntu", "Debian", "Rocky Linux"
}
OSInfo holds distribution identity parsed from /etc/os-release.
func GetOSInfo ¶ added in v1.2.0
GetOSInfo reads /etc/os-release from a SquashFS archive and returns an OSInfo. Returns nil if the file cannot be read or parsed.
func (*OSInfo) MajorVersion ¶ added in v1.2.0
MajorVersion returns the major component of VersionID (e.g., "24" from "24.04", "9" from "9.3").
func (*OSInfo) SameIDMajorVersion ¶ added in v1.2.0
SameIDMajorVersion returns true if both OSInfo values share the same id and major version.
type Profile ¶
type Profile struct {
InodeRatio int // -i: bytes per inode
ReservedPerc int // -m: percentage (0-100)
}
Profile defines the tuning parameters for the filesystem.
func GetProfile ¶ added in v1.3.0
GetProfile returns the Profile struct for a simple string name.
type SquashFSStats ¶ added in v1.2.0
type SquashFSStats struct {
CreatedTime string
FilesystemSizeBytes int64
Compression string
CompressionLevel int // 0 means not specified by the file
BlockSize int64
NumFragments int64
NumInodes int64
NumIDs int64
DuplicatesRemoved bool
ExportableNFS bool
}
SquashFSStats holds metadata parsed from `unsquashfs -stat`.
func GetSquashFSStats ¶ added in v1.2.0
func GetSquashFSStats(path string) (*SquashFSStats, error)
GetSquashFSStats runs `unsquashfs -stat` on the given path and parses its output.
type Stats ¶
type Stats struct {
// Filesystem metadata
FilesystemType string // "ext3", "ext4"
BlockSize int64
TotalBlocks int64
FreeBlocks int64
ReservedBlocks int64
TotalInodes int64
FreeInodes int64
FilesystemState string // "clean", "dirty", etc.
LastMounted string
CreatedTime string
FilesystemUUID string
JournalSize int64 // in blocks
InodeSize int64
// File metadata
FileSizeBytes int64 // Apparent size of the file
FileBlocksUsed int64 // Actual blocks allocated on disk (for sparse detection)
IsSparse bool // True if file is sparse
// Overlay ownership
UpperUID int
UpperGID int
}
Stats holds metadata about the overlay filesystem.
func (*Stats) InodeUsage ¶
InodeUsage returns the calculated inode usage percentage.
type UIDStatus ¶
type UIDStatus int
UIDStatus represents the result of InspectImageUIDStatus.
const ( UIDStatusUnknown UIDStatus = iota // UIDStatusRoot indicates the 'upper' directory is owned by root (UID 0). UIDStatusRoot // UIDStatusCurrentUser indicates it's owned by the current user. UIDStatusCurrentUser // UIDStatusDifferentUser indicates it's owned by a different user. UIDStatusDifferentUser )
func InspectImageUIDStatus ¶
InspectImageUIDStatus checks the ownership of the 'upper' directory inside an ext3/4 image. Returns:
- UIDStatusRoot: owned by root (UID 0)
- UIDStatusCurrentUser: owned by current user
- UIDStatusDifferentUser: owned by a different user
- UIDStatusUnknown: failed to check or not an image file
This is used to determine if --fakeroot should be automatically enabled.