Documentation
¶
Overview ¶
Package makefs provides function to format and grow filesystems.
Index ¶
- Constants
- func BTRFS(ctx context.Context, partname string, setters ...Option) error
- func BTRFSGrow(ctx context.Context, partname string) error
- func BTRFSRepair(ctx context.Context, partname string) error
- func Ext4(ctx context.Context, partname string, setters ...Option) error
- func Ext4Repair(ctx context.Context, partname string) error
- func Ext4Resize(ctx context.Context, partname string) error
- func GUIDFromLabel(label string) uuid.UUID
- func GenerateProtofile(sourcePath string) (io.Reader, error)
- func VFAT(ctx context.Context, partname string, setters ...Option) error
- func XFS(ctx context.Context, partname string, setters ...Option) error
- func XFSConcurrency(deviceSize, minAGSize uint64, numCPU int) optional.Optional[int]
- func XFSGrow(ctx context.Context, partname string) error
- func XFSRepair(ctx context.Context, partname string) error
- type Option
- func WithConfigFile(configFile string) Option
- func WithDeviceSize(size uint64) Option
- func WithForce(force bool) Option
- func WithLabel(label string) Option
- func WithMinAllocationGroupSize(size uint64) Option
- func WithPrintf(printf func(string, ...any)) Option
- func WithReproducible(reproducible bool) Option
- func WithSectorSize(sectorSize uint) Option
- func WithSourceDirectory(sourceDir string) Option
- func WithUnsupportedFSOption(unsupported bool) Option
- type Options
Constants ¶
const (
// FilesystemTypeBTRFS is the filesystem type for BTRFS.
FilesystemTypeBTRFS = "btrfs"
)
const (
// FilesystemTypeEXT4 is the filesystem type for EXT4.
FilesystemTypeEXT4 = "ext4"
)
const (
// FilesystemTypeVFAT is the filesystem type for VFAT.
FilesystemTypeVFAT = "vfat"
)
const (
// FilesystemTypeXFS is the filesystem type for XFS.
FilesystemTypeXFS = "xfs"
)
Variables ¶
This section is empty.
Functions ¶
func BTRFSGrow ¶
BTRFSGrow expands a BTRFS filesystem to the maximum possible.
The partition MUST be mounted, and partname must be a path within the mount (typically the mount point), since btrfs filesystem resize operates on a mounted filesystem.
func BTRFSRepair ¶
BTRFSRepair repairs a BTRFS filesystem on the specified partition.
As this operation is potentially dangerous, we are going to wire into the volume mount flow, but we will keep it here for completeness.
The filesystem must NOT be mounted. --force is passed to skip the interactive 10-second warning delay; --repair on a damaged filesystem is dangerous and can make things worse — callers should ensure a check is warranted.
func Ext4Repair ¶ added in v1.9.2
Ext4Repair repairs a ext4 filesystem.
func Ext4Resize ¶ added in v1.9.0
Ext4Resize expands a ext4 filesystem to the maximum possible.
func GUIDFromLabel ¶ added in v1.13.0
GUIDFromLabel generates a deterministic partition GUID from a label by creating a version 8 UUID derived from a SHA-256 hash of the label bytes.
func GenerateProtofile ¶ added in v1.13.0
GenerateProtofile walks a filesystem tree and generates an XFS protofile. All files and directories will have uid/gid mapped to 0:0.
func XFSConcurrency ¶
XFSConcurrency computes the value for the mkfs.xfs `concurrency=` option which keeps the allocation groups at or above minAGSize bytes.
On non-rotational devices mkfs.xfs sizes the allocation group count to the number of CPUs, bounding the allocation group size from below at 4 GiB only. On a machine with many cores and a modest disk that produces hundreds of tiny allocation groups, which squeezes the AG-local reflink/rmap metadata and inflates the journal at the same time. Capping the concurrency level restores a sane geometry.
The zero optional means that the option should not be passed at all (mkfs.xfs defaults apply). A value of 0 forces the classic geometry. 1 is never returned, as mkfs.xfs reads it as the magic "number of CPUs" value rather than as a literal count.
Types ¶
type Option ¶
type Option func(*Options)
Option to control makefs settings.
func WithConfigFile ¶ added in v1.10.0
WithConfigFile sets the config file for the filesystem to be created.
func WithDeviceSize ¶
WithDeviceSize sets the size of the device being formatted, in bytes.
It is only used to derive filesystem geometry, see WithMinAllocationGroupSize.
func WithMinAllocationGroupSize ¶
WithMinAllocationGroupSize sets the minimum allocation group size (in bytes) for XFS.
It has no effect unless WithDeviceSize is set as well. Zero leaves the mkfs defaults alone.
func WithPrintf ¶ added in v1.13.0
WithPrintf sets the printf function for logging.
func WithReproducible ¶ added in v1.5.0
WithReproducible sets the reproducible flag for the filesystem to be created. This should only be used when creating filesystems on raw disk images.
func WithSectorSize ¶
WithSectorSize overrides the sector size used by mkfs. This should only be used with disk images where the underlying sector size cannot be detected automatically; on real block devices mkfs auto-detection is preferred.
For ext4, this sets the filesystem block size (-b) since ext4 has no separate sector size concept.
func WithSourceDirectory ¶ added in v1.13.0
WithSourceDirectory sets the source directory for populating the filesystem.
func WithUnsupportedFSOption ¶ added in v1.8.0
WithUnsupportedFSOption sets the unsupported filesystem option.
type Options ¶
type Options struct {
Label string
ConfigFile string
SourceDirectory string
SectorSize uint
DeviceSize uint64
MinAllocationGroupSize uint64
Force bool
Reproducible bool
UnsupportedFSOption bool
Printf func(string, ...any)
}
Options for makefs.
func NewDefaultOptions ¶
NewDefaultOptions builds options with specified setters applied.