partitionhelper

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package partitionhelper contains code for manipulating with block device partitions and run such system utilites as parted, partprobe, sgdisk

Index

Constants

View Source
const (
	// PartitionGPT is the const for GPT partition table
	PartitionGPT = "gpt"

	// PartprobeDeviceCmdTmpl check that device has partition cmd
	PartprobeDeviceCmdTmpl = partprobe + "-d -s %s"
	// BlockdevCmdTmpl synchronize the partition table
	BlockdevCmdTmpl = blockdev + "--rereadpt -v %s"

	// CreatePartitionTableCmdTmpl create partition table on provided device of provided type cmd template
	// fill device and partition table type
	CreatePartitionTableCmdTmpl = sgdisk + "%s -o"
	// CreatePartitionCmdTmpl create partition on provided device cmd template, fill device and partition label
	CreatePartitionCmdTmpl = sgdisk + "-n 1:0:0 -c 1:%s %s"
	// CreatePartitionCmdWithUUIDTmpl create partition on provided device with uuid cmd template, fill device and partition label
	CreatePartitionCmdWithUUIDTmpl = sgdisk + "-n 1:0:0 -c 1:%s -u 1:%s %s"
	// DeletePartitionCmdTmpl delete partition from provided device cmd template, fill device and partition number
	DeletePartitionCmdTmpl = sgdisk + "-d %s %s"

	// DetectPartitionTableCmdTmpl is used to print information, which contain partition table
	DetectPartitionTableCmdTmpl = fdisk + "--list %s"

	// GetPartitionUUIDCmdTmpl command for read GUID of the first partition, fill device and part number
	GetPartitionUUIDCmdTmpl = sgdisk + "%s --info=%s"

	// NumberOfRetriesToSyncPartTable how many times to sync fs tab
	NumberOfRetriesToSyncPartTable = 15
	// SleepBetweenRetriesToSyncPartTable default timeout between fs tab sync attempt
	SleepBetweenRetriesToSyncPartTable = 3 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type WrapPartition

type WrapPartition interface {
	IsPartitionExists(device, partNum string) (exists bool, err error)
	GetPartitionTableType(device string) (ptType string, err error)
	CreatePartitionTable(device, partTableType string) (err error)
	CreatePartition(device, label, partUUID string) (err error)
	DeletePartition(device, partNum string) (err error)
	GetPartitionUUID(device, partNum string) (string, error)
	SyncPartitionTable(device string) (string, string, error)
	GetPartitionNameByUUID(device, partUUID string) (string, error)
	DeviceHasPartitionTable(device string) (bool, error)
	DeviceHasPartitions(device string) (bool, error)
}

WrapPartition is the interface which encapsulates methods to work with drives' partitions

type WrapPartitionImpl

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

WrapPartitionImpl is the basic implementation of WrapPartition interface

func NewWrapPartitionImpl

func NewWrapPartitionImpl(e command.CmdExecutor, log *logrus.Logger) *WrapPartitionImpl

NewWrapPartitionImpl is a constructor for WrapPartitionImpl instance

func NewWrapPartitionImplWithParameters added in v1.3.0

func NewWrapPartitionImplWithParameters(e command.CmdExecutor, log *logrus.Logger, numberOfRetriesToSyncPartTable int,
	sleepBetweenRetriesToSyncPartTable time.Duration) *WrapPartitionImpl

NewWrapPartitionImplWithParameters is a constructor for WrapPartitionImpl instance

func (*WrapPartitionImpl) CreatePartition

func (p *WrapPartitionImpl) CreatePartition(device, label, partUUID string) error

CreatePartition creates partition with name partName on a device Receives device path to create a partition Returns error if something went wrong

func (*WrapPartitionImpl) CreatePartitionTable

func (p *WrapPartitionImpl) CreatePartitionTable(device, partTableType string) error

CreatePartitionTable created partition table on a provided device Receives device path on which to create table Returns error if something went wrong

func (*WrapPartitionImpl) DeletePartition

func (p *WrapPartitionImpl) DeletePartition(device, partNum string) error

DeletePartition removes partition partNum from a provided device Receives device path and it's partition which should be deleted Returns error if something went wrong

func (*WrapPartitionImpl) DeviceHasPartitionTable

func (p *WrapPartitionImpl) DeviceHasPartitionTable(device string) (bool, error)

DeviceHasPartitionTable calls parted and determine if device has partition table from output Receive device path Return true if device has partition table, false in opposite, error if something went wrong

func (*WrapPartitionImpl) DeviceHasPartitions

func (p *WrapPartitionImpl) DeviceHasPartitions(device string) (bool, error)

DeviceHasPartitions calls lsblk and determine if device has partitions (children) Receive device path Return true if device has partitions, false in opposite, error if something went wrong

func (*WrapPartitionImpl) GetPartitionNameByUUID

func (p *WrapPartitionImpl) GetPartitionNameByUUID(device, partUUID string) (string, error)

GetPartitionNameByUUID gets partition name by it's UUID for example "1" for /dev/sda1, "1p2" for /dev/nvme1p2, "0p3" for /dev/loopback0p3 Receives a device path and uuid of partition to find Returns a partition number or error if something went wrong

func (*WrapPartitionImpl) GetPartitionTableType

func (p *WrapPartitionImpl) GetPartitionTableType(device string) (string, error)

GetPartitionTableType returns string that represent partition table type Receives device path from which partition table type should be got Returns partition table type as a string or error if something went wrong

func (*WrapPartitionImpl) GetPartitionUUID

func (p *WrapPartitionImpl) GetPartitionUUID(device, partNum string) (string, error)

GetPartitionUUID reads partition unique GUID from the partition partNum of a provided device Receives device path from which to read Returns unique GUID as a string or error if something went wrong

func (*WrapPartitionImpl) IsPartitionExists

func (p *WrapPartitionImpl) IsPartitionExists(device, partNum string) (bool, error)

IsPartitionExists checks if a partition exists in a provided device Receives path to a device to check a partition existence Returns partition existence status or error if something went wrong

func (*WrapPartitionImpl) SyncPartitionTable

func (p *WrapPartitionImpl) SyncPartitionTable(device string) (outStr string, errStr string, err error)

SyncPartitionTable syncs partition table for specific device Receives device path to sync with partprobe, device could be an empty string (sync for all devices in the system) Returns error if something went wrong

Jump to

Keyboard shortcuts

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