fs

package
v0.2.2-beta Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fs contains code for communicating with system file system utils such as mkdri/mkfs and so on

Index

Constants

View Source
const (
	// XFS file system
	XFS FileSystem = "xfs"
	// EXT4 file system
	EXT4 FileSystem = "ext4"
	// EXT3 file system
	EXT3 FileSystem = "ext3"

	// CheckSpaceCmdImpl cmd for getting space on the mounted FS, produce output in megabytes (--block-size=M)
	CheckSpaceCmdImpl = "df %s --output=target,avail --block-size=M" // add mounted fs part
	// MkFSCmdTmpl mkfs command template
	MkFSCmdTmpl = "mkfs.%s %s" // add fs type and device/path
	// SpeedUpFsCreationOpts options that could be used for speeds up creation of ext3 and ext4 FS
	SpeedUpFsCreationOpts = " -E lazy_journal_init=1,lazy_itable_init=1,discard"
	// MkDirCmdTmpl mkdir template
	MkDirCmdTmpl = "mkdir -p %s"
	// RmDirCmdTmpl rm template
	RmDirCmdTmpl = "rm -rf %s"
	// WipeFSCmdTmpl cmd for wiping FS on device
	WipeFSCmdTmpl = wipefs + "-af %s" //
	// DetectFSCmdTmpl cmd for detecting FS on device
	DetectFSCmdTmpl = "lsblk %s --output FSTYPE --noheadings"
	// GetFSTypeCmdTmpl cmd for retrieving FS type
	GetFSTypeCmdTmpl = wipefs + "%s --output TYPE --noheadings"
	// MountInfoFile "/proc/mounts" path
	MountInfoFile = "/proc/self/mountinfo"
	// FindMntCmdTmpl find source device for target mount path cmd
	FindMntCmdTmpl = "findmnt --target %s --output SOURCE --noheadings" // add target path
	// MountCmdTmpl mount cmd template, add "src" "dst" and "opts" (could be omitted)
	MountCmdTmpl = "mount %s %s %s"
	// UnmountCmdTmpl unmount path template
	UnmountCmdTmpl = "umount %s"
	// BindOption option for mount operation
	BindOption = "--bind"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem string

FileSystem is type for storing FS string representation

type WrapFS

type WrapFS interface {
	GetFSSpace(src string) (int64, error)
	MkDir(src string) error
	MkFile(src string) error
	RmDir(src string) error
	CreateFS(fsType FileSystem, device string) error
	WipeFS(device string) error
	GetFSType(device string) (FileSystem, error)
	// Mount operations
	IsMounted(src string) (bool, error)
	FindMountPoint(target string) (string, error)
	Mount(src, dst string, opts ...string) error
	Unmount(src string) error
	DeviceFs(device string) (string, error)
}

WrapFS is an interface that encapsulates operation with file systems

type WrapFSImpl

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

WrapFSImpl is a WrapFS implementer

func NewFSImpl

func NewFSImpl(e command.CmdExecutor) *WrapFSImpl

NewFSImpl is a constructor for WrapFSImpl struct

func (*WrapFSImpl) CreateFS

func (h *WrapFSImpl) CreateFS(fsType FileSystem, device string) error

CreateFS creates specified file system on the provided device using mkfs Receives file system as a var of FileSystem type and path of the device as a string Returns error if something went wrong

func (*WrapFSImpl) DeviceFs

func (h *WrapFSImpl) DeviceFs(device string) (string, error)

DeviceFs detect FS from the provided device using lsblk --output FSTYPE Receives file path of the device as a string Returns error if something went wrong

func (*WrapFSImpl) FindMountPoint

func (h *WrapFSImpl) FindMountPoint(target string) (string, error)

FindMountPoint returns source of mount point for target Receives path of a mount point as target Returns mount point or empty string and error

func (*WrapFSImpl) GetFSSpace

func (h *WrapFSImpl) GetFSSpace(src string) (int64, error)

GetFSSpace calls df command and return available space on the provided file system (src) Returns free bytes as int64 or error if something went wrong

func (*WrapFSImpl) GetFSType

func (h *WrapFSImpl) GetFSType(device string) (FileSystem, error)

GetFSType returns FS type on the device or error

func (*WrapFSImpl) IsMounted

func (h *WrapFSImpl) IsMounted(path string) (bool, error)

IsMounted checks if the path is presented in /proc/self/mountinfo Receives path as a string Returns bool that represents mount status or error if something went wrong

func (*WrapFSImpl) MkDir

func (h *WrapFSImpl) MkDir(src string) error

MkDir creates specified path using mkdir if it doesn't exist Receives directory path to create as a string Returns error if something went wrong

func (*WrapFSImpl) MkFile

func (h *WrapFSImpl) MkFile(src string) error

MkFile create file with specified path

func (*WrapFSImpl) Mount

func (h *WrapFSImpl) Mount(src, dir string, opts ...string) error

Mount mounts source path to the destination directory Receives source path and destination dir and also opts parameters that are used for mount command for example --bind Returns error if something went wrong

func (*WrapFSImpl) RmDir

func (h *WrapFSImpl) RmDir(src string) error

RmDir removes specified path using rm Receives directory of file path to delete as a string Returns error if something went wrong

func (*WrapFSImpl) Unmount

func (h *WrapFSImpl) Unmount(path string) error

Unmount unmounts device from the specified path Receives path where the device is mounted Returns error if something went wrong

func (*WrapFSImpl) WipeFS

func (h *WrapFSImpl) WipeFS(device string) error

WipeFS deletes file system from the provided device using wipefs Receives file path of the device as a string Returns error if something went wrong

Jump to

Keyboard shortcuts

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