Documentation
¶
Overview ¶
Package disk provides utilities for disk operations.
Index ¶
- func DefaultMatchFuncDeviceType(deviceType string) bool
- func DefaultMatchFuncFstype(fs string) bool
- func FindMntTargetDevice(target string) (string, error)
- type BlockDevice
- type BlockDevices
- type CustomBool
- type CustomInt64
- type MatchFunc
- type Op
- type OpOption
- type Partition
- type Partitions
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMatchFuncFstype ¶
func FindMntTargetDevice ¶
FindMntTargetDevice retrieves mount information for a given target directory. Implements "findmnt --target [DIRECTORY]". It returns an empty string and no error if the target is not found.
Types ¶
type BlockDevice ¶
type BlockDevice struct {
Name string `json:"name,omitempty"`
ParentDeviceName string `json:"parent_device_name,omitempty"`
Type string `json:"type,omitempty"`
Size CustomInt64 `json:"size,omitempty"`
SizeHumanized string `json:"size_humanized,omitempty"`
Rota CustomBool `json:"rota,omitempty"`
Serial string `json:"serial,omitempty"`
WWN string `json:"wwn,omitempty"`
Vendor string `json:"vendor,omitempty"`
Model string `json:"model,omitempty"`
Rev string `json:"rev,omitempty"`
MountPoint string `json:"mountpoint,omitempty"`
FSType string `json:"fstype,omitempty"`
PartUUID string `json:"partuuid,omitempty"`
Children []BlockDevice `json:"children,omitempty"`
}
BlockDevice is the struct that represents output of lsblk command for a device
type BlockDevices ¶
type BlockDevices []BlockDevice
func GetBlockDevices ¶
func GetBlockDevices(ctx context.Context, opts ...OpOption) (BlockDevices, error)
GetBlockDevices run os lsblk command for device and construct BlockDevice struct based on output Receives device path. If device is empty string, info about all devices will be collected Returns slice of BlockDevice structs or error if something went wrong
func (BlockDevices) GetTotalBytes ¶
func (blks BlockDevices) GetTotalBytes() uint64
Returns the total bytes of all block devices.
func (BlockDevices) JSON ¶
func (blks BlockDevices) JSON() ([]byte, error)
func (BlockDevices) RenderTable ¶
func (blks BlockDevices) RenderTable(wr io.Writer)
func (BlockDevices) YAML ¶
func (blks BlockDevices) YAML() ([]byte, error)
type CustomBool ¶
type CustomBool struct {
Bool bool
}
CustomBool to handle Rota lsblk output - true/false or "1"/"0"
func (CustomBool) MarshalJSON ¶
func (cb CustomBool) MarshalJSON() ([]byte, error)
MarshalJSON customizes rota marshaling
func (*CustomBool) UnmarshalJSON ¶
func (cb *CustomBool) UnmarshalJSON(data []byte) error
UnmarshalJSON customizes string rota unmarshaling
type CustomInt64 ¶
type CustomInt64 struct {
Int64 int64
}
CustomInt64 to handle Size lsblk output - 8001563222016 or "8001563222016"
func (*CustomInt64) MarshalJSON ¶
func (ci *CustomInt64) MarshalJSON() ([]byte, error)
MarshalJSON customizes size marshaling
func (*CustomInt64) UnmarshalJSON ¶
func (ci *CustomInt64) UnmarshalJSON(data []byte) error
UnmarshalJSON customizes string size unmarshaling
type Partitions ¶
type Partitions []Partition
func GetPartitions ¶
func GetPartitions(ctx context.Context, opts ...OpOption) (Partitions, error)
func (Partitions) GetMountedTotalBytes ¶
func (parts Partitions) GetMountedTotalBytes() uint64
Returns the total bytes of all mounted partitions.
func (Partitions) JSON ¶
func (parts Partitions) JSON() ([]byte, error)
func (Partitions) RenderTable ¶
func (parts Partitions) RenderTable(wr io.Writer)
func (Partitions) YAML ¶
func (parts Partitions) YAML() ([]byte, error)
type Usage ¶
type Usage struct {
TotalBytes uint64 `json:"total_bytes"`
TotalHumanized string `json:"total_humanized"`
FreeBytes uint64 `json:"free_bytes"`
FreeHumanized string `json:"free_humanized"`
UsedBytes uint64 `json:"used_bytes"`
UsedHumanized string `json:"used_humanized"`
UsedPercent string `json:"used_percent"`
UsedPercentFloat float64 `json:"-"`
InodesTotal uint64 `json:"inodes_total"`
InodesUsed uint64 `json:"inodes_used"`
InodesFree uint64 `json:"inodes_free"`
InodesUsedPercent string `json:"inodes_used_percent"`
InodesUsedPercentFloat float64 `json:"-"`
}