fs

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 9 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 %s" // args: 1 - fs type, 2 - device/path, 3 - fs uuid option
	// XfsUUIDOption option to set uuid for mkfs.xfs
	XfsUUIDOption = "-m uuid=%s"
	// ExtUUIDOption option to set uuid for mkfs.ext3(4)
	ExtUUIDOption = "-U %s"
	// 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" //
	// GetFSTypeCmdTmpl cmd for detecting FS on device
	GetFSTypeCmdTmpl = "lsblk %s --output FSTYPE --noheadings"
	// GetFsUUIDCmdTmpl cmd for detecting FS on device
	GetFsUUIDCmdTmpl = "lsblk %s --output UUID --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"
	// MountOptionsFlag flag to set mount options
	MountOptionsFlag = "-o"
	// CreateFileByDDCmdTmpl cmd for creating file with specified size by dd command
	CreateFileByDDCmdTmpl = "dd if=/dev/zero of=%s bs=1M count=%s"
	// ReadLoopBackDeviceMappingCmd cmd for reading loopback device mapping
	ReadLoopBackDeviceMappingCmd = losetupCmd + "-O NAME,BACK-FILE %s"
	// SetupLoopBackDeviceCmdTmpl cmd for loopback device setup
	SetupLoopBackDeviceCmdTmpl = losetupCmd + "-f --show %s"
	// DetachLoopBackDeviceCmdTmpl cmd for loopback device detach
	DetachLoopBackDeviceCmdTmpl = losetupCmd + "-d %s"

	// NoSuchDeviceErrMsg is the err msg in stderr of the cmd output when specified device cannot be found
	NoSuchDeviceErrMsg = "No such device"
)

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, uuid string) error
	WipeFS(device string) error
	GetFSType(device string) (string, error)
	GetFSUUID(device string) (string, error)
	// Mount operations
	IsMounted(src string) (bool, error)
	FindMountPoint(target string) (string, error)
	Mount(src, dst string, opts ...string) error
	Unmount(src string) error
	CreateFileWithSizeInMB(filePath string, sizeMB int) error
	ReadLoopDevice(device string) (string, error)
	CreateLoopDevice(src string) (string, error)
	RemoveLoopDevice(device 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, uuid 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) CreateFileWithSizeInMB added in v1.4.0

func (h *WrapFSImpl) CreateFileWithSizeInMB(filePath string, sizeMB int) error

CreateFileWithSizeInMB creates file with specified size in MB unit by dd command Receives the file path and size in MB unit Returns error if something went wrong

func (*WrapFSImpl) CreateLoopDevice added in v1.4.0

func (h *WrapFSImpl) CreateLoopDevice(src string) (string, error)

CreateLoopDevice create loopback device mapped to specified src Receives the file path of the specified src, whether a regular file or block device Returns the loopback device's file path or empty string and 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) (string, error)

GetFSType detect FS type 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) GetFSUUID added in v1.3.0

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

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

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) ReadLoopDevice added in v1.4.0

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

ReadLoopDevice get loopback device's mapped backing file Receives the specified device's path Returns the loopback device's mapped backing file or empty string and error if something went wrong

func (*WrapFSImpl) RemoveLoopDevice added in v1.4.0

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

RemoveLoopDevice remove the specified loopback device Receives the loop device path 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