mount

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package mount handles filesystem mount operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindReadonly

func BindReadonly(src, dst string) error

BindReadonly creates a common way to create a readonly bind mounted destination.

func BindReadonlyFd

func BindReadonlyFd(dfd int, dst string) error

BindReadonlyFd creates a common way to create a readonly bind mounted destination.

func SafeUnmount

func SafeUnmount(ctx context.Context, printer func(string, ...any), target string) error

SafeUnmount unmounts the target path, first without force, then with force if the first attempt fails.

It makes sure that unmounting has a finite operation timeout.

func UnmountAll

func UnmountAll() error

UnmountAll attempts to unmount all the mounted filesystems via "self" mountinfo.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the filesystem manager for mounting and unmounting filesystems.

func NewCgroup2

func NewCgroup2() *Manager

NewCgroup2 creates a new cgroup2 filesystem.

func NewManager

func NewManager(opts ...ManagerOption) *Manager

NewManager creates a new Manager with the given options.

func NewOverlayWithBasePath

func NewOverlayWithBasePath(sources []string, target, basePath string, printer func(string, ...any), options ...ManagerOption) *Manager

NewOverlayWithBasePath creates a new overlay filesystem with a base path.

func NewReadOnlyOverlay

func NewReadOnlyOverlay(sources []string, target string, printer func(string, ...any), options ...ManagerOption) *Manager

NewReadOnlyOverlay creates a new read-only overlay filesystem.

func NewSystemOverlay

func NewSystemOverlay(sources []string, target string, printer func(string, ...any), options ...ManagerOption) *Manager

NewSystemOverlay creates a new /system overlay filesystem.

func NewVarOverlay

func NewVarOverlay(sources []string, target string, printer func(string, ...any), options ...ManagerOption) *Manager

NewVarOverlay creates a new /var overlay filesystem.

func Squashfs

func Squashfs(target, squashfsFile string, printer func(string, ...any)) (*Manager, error)

Squashfs binds the squashfs to the loop device and returns the mountpoint for it to the specified target.

func (*Manager) Mount

func (m *Manager) Mount() (*Point, error)

Mount mounts a filesystem with the given options.

func (*Manager) Move

func (m *Manager) Move(newTarget string) error

Move the mount point to a new target.

func (*Manager) Unmount

func (m *Manager) Unmount() error

Unmount the mount point.

type ManagerOption

type ManagerOption struct {
	// contains filtered or unexported fields
}

ManagerOption is an option for configuring the Manager.

func WithDetached

func WithDetached() ManagerOption

WithDetached sets the mount as detached.

func WithExtraDirs

func WithExtraDirs(dirs ...string) ManagerOption

WithExtraDirs adds extra dirs to the manager that should be created prior to mounting the filesystem.

func WithExtraUnmountCallbacks

func WithExtraUnmountCallbacks(callbacks ...func(m *Manager)) ManagerOption

WithExtraUnmountCallbacks adds extra callbacks to the unmount operation. Those need to handle errors by themselves.

func WithFsopen

func WithFsopen(fstype string, opts ...fsopen.Option) ManagerOption

WithFsopen sets the filesystem opener with the given type and options.

func WithKeepOpenAfterMount

func WithKeepOpenAfterMount() ManagerOption

WithKeepOpenAfterMount assesses if the mountpoint fd should be kept open after the Mount.

func WithMountAttributes

func WithMountAttributes(flags int) ManagerOption

WithMountAttributes sets the mount attributes.

func WithOpentreeFromPath

func WithOpentreeFromPath(path string) ManagerOption

WithOpentreeFromPath sets the opentree opener with the path.

func WithPrinter

func WithPrinter(printer func(string, ...any)) ManagerOption

WithPrinter sets the printer function for logging.

func WithReadOnly

func WithReadOnly() ManagerOption

WithReadOnly sets the mount as read only.

func WithSelinuxLabel

func WithSelinuxLabel(label string) ManagerOption

WithSelinuxLabel sets the mount SELinux label.

func WithShared

func WithShared() ManagerOption

WithShared sets the mount as shared.

func WithSkipIfMounted

func WithSkipIfMounted() ManagerOption

WithSkipIfMounted sets the option to skip mounting if already mounted.

func WithTarget

func WithTarget(target string) ManagerOption

WithTarget sets the target mount point.

type Managers

type Managers []*Manager

Managers is a list of mount managers.

func Pseudo

func Pseudo(printer func(string, ...any)) Managers

Pseudo creates basic filesystem mountpoint managers.

func PseudoLate

func PseudoLate(printer func(string, ...any)) Managers

PseudoLate creates late pseudo filesystem mountpoint managers.

func PseudoSub

func PseudoSub(printer func(string, ...any)) Managers

PseudoSub creates additional pseudo filesystem mountpoint managers.

func (Managers) Mount

func (managers Managers) Mount() (func() error, error)

Mount all mount points managed by managers.

func (Managers) Move

func (managers Managers) Move(prefix string) error

Move all mount managers to a new prefix.

func (Managers) Unmount

func (managers Managers) Unmount() error

Unmount all mount points managed by managers.

type Options

type Options struct {
	SkipIfMounted   bool
	MountAttributes int
	Shared          bool
	Printer         func(string, ...any)
}

Options represents options for mounting a mount point.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point represents a mount point in the filesystem.

func NewPoint

func NewPoint(source string, srcfd int, target string, targetfd int, fstype string) *Point

NewPoint creates a new mount point.

func (*Point) FSType

func (p *Point) FSType() string

FSType returns the filesystem type of the mount point.

func (*Point) IsMounted

func (p *Point) IsMounted() (bool, error)

IsMounted checks if the mount point is mounted by checking the mount on the target.

func (*Point) Mount

func (p *Point) Mount(opts Options) error

Mount the mount point.

func (*Point) Move

func (p *Point) Move(newTarget string) error

Move the mount point to a new target.

func (*Point) Release

func (p *Point) Release(force bool) error

Release closes the file descriptor of the underlying mount point.

func (*Point) RemountReadOnly

func (p *Point) RemountReadOnly() error

RemountReadOnly remounts the mount point as read-only.

func (*Point) RemountReadWrite

func (p *Point) RemountReadWrite() error

RemountReadWrite remounts the mount point as read-write.

func (*Point) Root

func (p *Point) Root() xfs.Root

Root returns the underlying xfs.Root of the mount point.

func (*Point) Share

func (p *Point) Share() error

Share makes the mount point shared.

func (*Point) Source

func (p *Point) Source() string

Source returns the source of the mount point.

func (*Point) Target

func (p *Point) Target() string

Target returns the target of the mount point.

func (*Point) Unmount

func (p *Point) Unmount(opts UnmountOptions) error

Unmount unmounts the mount point, retrying on certain errors.

type UnmountOptions

type UnmountOptions struct {
	Printer func(string, ...any)
}

UnmountOptions represents options for unmounting a mount point.

Jump to

Keyboard shortcuts

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