system

package
v0.0.0-...-79e20a7 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-2-Clause-Patent Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	FsTypeNone    = "none"
	FsTypeExt4    = "ext4"
	FsTypeBtrfs   = "btrfs"
	FsTypeXfs     = "xfs"
	FsTypeZfs     = "zfs"
	FsTypeNtfs    = "ntfs"
	FsTypeTmpfs   = "tmpfs"
	FsTypeNfs     = "nfs"
	FsTypeUnknown = "unknown"

	// magic numbers harvested from statfs man page
	MagicTmpfs = 0x01021994
	MagicExt4  = 0xEF53
	MagicBtrfs = 0x9123683E
	MagicXfs   = 0x58465342
	MagicZfs   = 0x2FC12FC1
	MagicNtfs  = 0x5346544e
	MagicNfs   = 0x6969
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Distribution

type Distribution struct {
	ID      string              `json:"id"`
	Name    string              `json:"name"`
	Version DistributionVersion `json:"version"`
	Kernel  KernelVersion       `json:"kernel"`
}

Distribution represents a Linux distribution.

func GetDistribution

func GetDistribution() Distribution

GetDistribution returns information about the current Linux distribution.

func (Distribution) String

func (d Distribution) String() string

type DistributionVersion

type DistributionVersion struct {
	StringVersion string `json:"string_version"`
	Major         int    `json:"major"`
	Minor         int    `json:"minor"`
	Patch         int    `json:"patch"`
}

DistributionVersion represents a version of a Linux distribution.

func (DistributionVersion) String

func (dv DistributionVersion) String() string

type FsType

type FsType struct {
	Name   string
	NoSUID bool
}

type GetfsUsageRetval

type GetfsUsageRetval struct {
	Total, Avail uint64
	Err          error
}

GetfsUsageRetval encapsulates return values from a GetfsUsage call.

type IsMountedProvider

type IsMountedProvider interface {
	IsMounted(target string) (bool, error)
}

IsMountedProvider is the interface that wraps the IsMounted method, which can be provided by a system-specific implementation or a mock.

type KernelVersion

type KernelVersion struct {
	Major int
	Minor int
	Patch int
}

KernelVersion is the kernel version.

type LinuxProvider

type LinuxProvider struct{}

LinuxProvider encapsulates Linux-specific implementations of system interfaces.

func DefaultProvider

func DefaultProvider() *LinuxProvider

DefaultProvider returns the package-default provider implementation.

func (LinuxProvider) Chmod

func (s LinuxProvider) Chmod(path string, mode os.FileMode) error

Chmod changes the mode of the specified path.

func (LinuxProvider) Chown

func (s LinuxProvider) Chown(path string, uid, gid int) error

Chown changes the ownership of the specified path.

func (LinuxProvider) GetFsType

func (s LinuxProvider) GetFsType(path string) (*FsType, error)

GetFsType retrieves the filesystem type for a path.

func (LinuxProvider) Getfs

func (s LinuxProvider) Getfs(device string) (string, error)

Getfs probes the specified device in an attempt to determine the formatted filesystem type, if any.

func (LinuxProvider) GetfsUsage

func (s LinuxProvider) GetfsUsage(target string) (uint64, uint64, error)

GetfsUsage retrieves total and available byte counts for a mountpoint.

func (LinuxProvider) IsMounted

func (s LinuxProvider) IsMounted(target string) (bool, error)

IsMounted checks the target device or directory for mountedness.

func (LinuxProvider) Mkfs

func (s LinuxProvider) Mkfs(req MkfsReq) error

Mkfs attempts to create a filesystem of the supplied type, on the supplied device.

func (LinuxProvider) Mount

func (s LinuxProvider) Mount(source, target, fstype string, flags uintptr, data string) error

Mount provides an implementation of Mounter which calls the system implementation.

func (LinuxProvider) Stat

func (s LinuxProvider) Stat(path string) (os.FileInfo, error)

Stat probes the specified path and returns os level file info.

func (LinuxProvider) Unmount

func (s LinuxProvider) Unmount(target string, flags int) error

Unmount provides an implementation of Unmounter which calls the system implementation.

type MkfsReq

type MkfsReq struct {
	Device     string
	Filesystem string
	Options    []string
	Force      bool
}

MkfsReq defines the input parameters for a Mkfs call.

type MockSysConfig

type MockSysConfig struct {
	IsMountedBool   bool
	IsMountedErr    error
	MountErr        error
	UnmountErr      error
	MkfsErr         error
	ChmodErr        error
	ChownErr        error
	GetfsStr        string
	GetfsErr        error
	SourceToTarget  map[string]string
	GetfsIndex      int
	GetfsUsageResps []GetfsUsageRetval
	GetFsTypeRes    *FsType
	GetFsTypeErr    []error
	StatErrors      map[string]error
	RealStat        bool
}

MockSysConfig alters mock SystemProvider behavior.

type MockSysProvider

type MockSysProvider struct {
	sync.RWMutex

	IsMountedInputs []string
	GetFsTypeCount  int
	// contains filtered or unexported fields
}

MockSysProvider gives a mock SystemProvider implementation.

func DefaultMockSysProvider

func DefaultMockSysProvider(log logging.Logger) *MockSysProvider

func NewMockSysProvider

func NewMockSysProvider(log logging.Logger, cfg *MockSysConfig) *MockSysProvider

func (*MockSysProvider) Chmod

func (msp *MockSysProvider) Chmod(string, os.FileMode) error

func (*MockSysProvider) Chown

func (msp *MockSysProvider) Chown(string, int, int) error

func (*MockSysProvider) GetFsType

func (msp *MockSysProvider) GetFsType(path string) (*FsType, error)

func (*MockSysProvider) GetMountOpts

func (msp *MockSysProvider) GetMountOpts(target string) (string, error)

func (*MockSysProvider) Getfs

func (msp *MockSysProvider) Getfs(_ string) (string, error)

func (*MockSysProvider) GetfsUsage

func (msp *MockSysProvider) GetfsUsage(_ string) (uint64, uint64, error)

func (*MockSysProvider) IsMounted

func (msp *MockSysProvider) IsMounted(target string) (bool, error)

func (*MockSysProvider) Mkfs

func (msp *MockSysProvider) Mkfs(_ MkfsReq) error

func (*MockSysProvider) Mount

func (msp *MockSysProvider) Mount(_, target, _ string, _ uintptr, opts string) error

func (*MockSysProvider) Stat

func (msp *MockSysProvider) Stat(path string) (os.FileInfo, error)

func (*MockSysProvider) Unmount

func (msp *MockSysProvider) Unmount(target string, _ int) error

type MountMap

type MountMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*MountMap) Get

func (mm *MountMap) Get(mount string) (string, bool)

func (*MountMap) Set

func (mm *MountMap) Set(mount string, mountOpts string)

type MountProvider

type MountProvider interface {
	Mount(source, target, fstype string, flags uintptr, data string) error
}

MountProvider is the interface that wraps the Mount method, which can be provided by a system-specific implementation or a mock.

type RunCmdError

type RunCmdError struct {
	Wrapped error  // Error from the command run
	Stdout  string // Standard output from the command
}

RunCmdError documents the output of a command that has been run.

func (*RunCmdError) Error

func (rce *RunCmdError) Error() string

type UnmountProvider

type UnmountProvider interface {
	Unmount(target string, flags int) error
}

UnmountProvider is the interface that wraps the Unmount method, which can be provided by a system-specific implementation or a mock.

Jump to

Keyboard shortcuts

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