Documentation ¶
Overview ¶
Package partitionhelper contains code for manipulating with block device partitions and run such system utilites as parted, partprobe, sgdisk
Index ¶
- Constants
- type WrapPartition
- type WrapPartitionImpl
- func (p *WrapPartitionImpl) CreatePartition(device, label string) error
- func (p *WrapPartitionImpl) CreatePartitionTable(device, partTableType string) error
- func (p *WrapPartitionImpl) DeletePartition(device, partNum string) error
- func (p *WrapPartitionImpl) DeviceHasPartitionTable(device string) (bool, error)
- func (p *WrapPartitionImpl) DeviceHasPartitions(device, serialNumber string) (bool, error)
- func (p *WrapPartitionImpl) GetPartitionNameByUUID(device, partUUID string) (string, error)
- func (p *WrapPartitionImpl) GetPartitionTableType(device string) (string, error)
- func (p *WrapPartitionImpl) GetPartitionUUID(device, partNum string) (string, error)
- func (p *WrapPartitionImpl) IsPartitionExists(device, partNum string) (bool, error)
- func (p *WrapPartitionImpl) SetPartitionUUID(device, partNum, partUUID string) error
- func (p *WrapPartitionImpl) SyncPartitionTable(device string) error
Constants ¶
const ( // PartitionGPT is the const for GPT partition table PartitionGPT = "gpt" // PartprobeDeviceCmdTmpl check that device has partition cmd PartprobeDeviceCmdTmpl = partprobe + "-d -s %s" // PartprobeCmdTmpl check device has partition with partprobe cmd PartprobeCmdTmpl = partprobe + "%s" // CreatePartitionTableCmdTmpl create partition table on provided device of provided type cmd template // fill device and partition table type CreatePartitionTableCmdTmpl = parted + "-s %s mklabel %s" // CreatePartitionCmdTmpl create partition on provided device cmd template, fill device and partition label CreatePartitionCmdTmpl = parted + "-s %s mkpart --align optimal %s 0%% 100%%" // DeletePartitionCmdTmpl delete partition from provided device cmd template, fill device and partition number DeletePartitionCmdTmpl = parted + "-s %s rm %s" // DetectPartitionTableCmdTmpl is used to print information, which contain partition table DetectPartitionTableCmdTmpl = fdisk + "--list %s" // SetPartitionUUIDCmdTmpl command for set GUID of the partition, fill device, part number and part UUID SetPartitionUUIDCmdTmpl = sgdisk + "%s --partition-guid=%s:%s" // GetPartitionUUIDCmdTmpl command for read GUID of the first partition, fill device and part number GetPartitionUUIDCmdTmpl = sgdisk + "%s --info=%s" )
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 string) (err error) DeletePartition(device, partNum string) (err error) SetPartitionUUID(device, partNum, partUUID string) error GetPartitionUUID(device, partNum string) (string, error) SyncPartitionTable(device string) error GetPartitionNameByUUID(device, partUUID string) (string, error) DeviceHasPartitionTable(device string) (bool, error) DeviceHasPartitions(device, serialNumber 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 (*WrapPartitionImpl) CreatePartition ¶
func (p *WrapPartitionImpl) CreatePartition(device, label 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, serialNumber string) (bool, error)
DeviceHasPartitions calls lsblk and determine if device has partitions (children) Receive device path and serial number 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) SetPartitionUUID ¶
func (p *WrapPartitionImpl) SetPartitionUUID(device, partNum, partUUID string) error
SetPartitionUUID writes partUUID as GUID for the partition partNum of a provided device Receives device path and partUUID as strings Returns error if something went wrong
func (*WrapPartitionImpl) SyncPartitionTable ¶
func (p *WrapPartitionImpl) SyncPartitionTable(device string) 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