libmount

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package libmount provides utilties to parse and operate on the various mount files (fstab, mtab, mounts, mountinfo, etc.). This package is a pure go implementation of the util-linux/libmount C library - https://github.com/karelzak/util-linux/tree/master/libmount

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument error = errors.New("invalid argument provided")
	ErrFilesystemBusy  error = errors.New("filesystem busy")
	ErrDeniedByFilters error = errors.New("fs denied by filters")
)
View Source
var (
	ErrInvalidToken error = errors.New("invalid token error")
)

Functions

This section is empty.

Types

type Filesystem

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

Filesystem represents a single filesystem entry in a mount table.

func NewFilesystem

func NewFilesystem() *Filesystem

NewFilesystem returns an empty filesystem

func (*Filesystem) GetFSOptions

func (fs *Filesystem) GetFSOptions() string

GetFsOptions returns the fs options of the filesystem

func (*Filesystem) GetID

func (fs *Filesystem) GetID() int

GetID returns the id of the filesystem

func (*Filesystem) GetMountTable

func (fs *Filesystem) GetMountTable() *MountTab

GetMountTable returns a pointer to the mount tab this filesystem is a part of. nil if the filesystem isn't a part of any mount tab.

func (*Filesystem) GetSource

func (fs *Filesystem) GetSource() string

GetSource returns the source device of the filesystem

func (*Filesystem) GetTarget

func (fs *Filesystem) GetTarget() string

GetTarget returns the target path of the filesystem

func (*Filesystem) GetVFSOptions

func (fs *Filesystem) GetVFSOptions() string

GetVFSOptions returns the vfs options of the filesystem

func (*Filesystem) SetFsType

func (fs *Filesystem) SetFsType(fsType string)

SetFsType sets the filsystem type of the filesystem Eg: ext4, vfat, etc.

func (*Filesystem) SetMountTable

func (fs *Filesystem) SetMountTable(tab *MountTab)

SetMountTable sets the mount tab that this filesystem is a part of. A filesystem can only be a part of a single mount tab.

func (*Filesystem) SetSource

func (fs *Filesystem) SetSource(src string)

SetSource sets the source device of the filesystem

func (*Filesystem) SetTag

func (fs *Filesystem) SetTag(name string, value string)

SetTag sets the tag for the filesystem

func (*Filesystem) SetTarget

func (fs *Filesystem) SetTarget(target string)

SetTarget sets the target path of the filesystem

type FsFilter

type FsFilter func(*Filesystem) bool

func IDFilter

func IDFilter(id int) FsFilter

IDFilter returns a filter that can be used to filter filesystems by matching id values.

func SourceContainsFilter

func SourceContainsFilter(substr string) FsFilter

SourceContainsFilter returns a filter that can be used to filter filesystems by checking if the source contains the given substring.

func SourceFilter

func SourceFilter(source string) FsFilter

SourceFilter returns a filter that can be used to filter filesystems by matching the source value.

func TargetContainsFilter

func TargetContainsFilter(substr string) FsFilter

TargetContainsFilter returns a filter that can be used to filter filesystems by checking if the target contains the given substring.

func TargetFilter

func TargetFilter(target string) FsFilter

TargetFilter returns a filter that can be used to filter filesystems by matching target values.

type MountAction

type MountAction uint8
const (
	MountActionMount MountAction = iota
	MountActionUmount
	MountActionMove
	MountActionRemount
)

type MountTab

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

MountTab represents a mount table that may contain multiple filesystem entries

func NewMountTab

func NewMountTab(opts ...MountTabOpt) (*MountTab, error)

NewMountTab initializes and returns a new mount tab configured with the given options

func (*MountTab) AddFilesystem

func (mt *MountTab) AddFilesystem(fs *Filesystem) error

AddFilesystem adds a filesystem to the mount tab.

func (*MountTab) Entries

func (mt *MountTab) Entries() []*Filesystem

Entries returns all the filesystem entries in the mount tab.

func (*MountTab) Find

func (mt *MountTab) Find(filters ...FsFilter) *Filesystem

Find returns the first filesystem entry in the mount tab that passes all the given filters.

func (*MountTab) Size

func (mt *MountTab) Size() int

Size returns the number of filesystems present in the mount tab

type MountTabDiff

type MountTabDiff []*MountTabDiffEntry

MountTabDiff is the list of all changes between two mount tabs.

func GenerateDiff

func GenerateDiff(oldTab *MountTab, newTab *MountTab) MountTabDiff

GenerateDiff returns a list of changes between the old mount tab and the new mount tab in the form of a MountTabDiff. A nil value for any of the parameters is valid and is treated as a mount tab with no entries.

func NewMountTabDiff

func NewMountTabDiff() MountTabDiff

NewMountTabDiff returns a new and empty MountTabDiff

func (MountTabDiff) AddDiffEntry

func (md MountTabDiff) AddDiffEntry(oldFs *Filesystem, newFs *Filesystem, action MountAction) MountTabDiff

AddDiffEntry returns a new MountTabDiff containing all the entries of the current MountTabDiff and a new entry appended based on the parametrs.

func (MountTabDiff) ListSources

func (md MountTabDiff) ListSources() []string

ListSources lists all affected sources in the diff, i.e., all sources that were mounted/umounted/remounted/moved in the diff.

type MountTabDiffEntry

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

MountTabDiffEntry represents a single change entry in the MounTabDiff

func (*MountTabDiffEntry) GetAction

func (mde *MountTabDiffEntry) GetAction() MountAction

GetAction returns the type of change - mount, umount, move, remount

func (*MountTabDiffEntry) GetNewFs

func (mde *MountTabDiffEntry) GetNewFs() *Filesystem

GetNewFs returns a pointer to the new filesystem that the old filesystem changed to.

func (*MountTabDiffEntry) GetOldFs

func (mde *MountTabDiffEntry) GetOldFs() *Filesystem

GetOldFs returns a pointer to the old filesystem that changed

type MountTabFormat

type MountTabFormat int
const (
	MntFmtGuess MountTabFormat = iota
	MntFmtFstab
	MntFmtMountInfo
	MntFmtUtab
	MntFmtSwaps
	MntFmtMtab = MntFmtFstab
)

type MountTabOpt

type MountTabOpt func(*MountTab) error

func FromFile

func FromFile(fileName string, format MountTabFormat) MountTabOpt

FromFile option tells NewMountTab to fill the mount tab from the specified file.

func WithAllowFilter

func WithAllowFilter(filter FsFilter) MountTabOpt

WithAllowFilter option tells NewMountTab to add the given filter to mount tab as an allow filter.

func WithDenyFilter

func WithDenyFilter(filter FsFilter) MountTabOpt

WithDenyFilter option tells NewMountTab to add the given filter to mount tab as a deny filter.

type Parser

type Parser interface {
	Parse(string) (*Filesystem, error)
}

func NewMountInfoParser

func NewMountInfoParser() Parser

func NewMountsParser

func NewMountsParser() Parser

func NewParser

func NewParser(format MountTabFormat) Parser

Jump to

Keyboard shortcuts

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