Documentation ¶
Overview ¶
Package block provides support for operations on blockdevices.
Index ¶
- Constants
- type Device
- func (d *Device) Close() error
- func (d *Device) FastWipe() error
- func (d *Device) File() *os.File
- func (d *Device) GetDevNo() (uint64, error)
- func (d *Device) GetIOSize() (uint, error)
- func (d *Device) GetKernelLastPartitionNum() (int, error)
- func (d *Device) GetProperties() (*DeviceProperties, error)
- func (d *Device) GetSectorSize() uint
- func (d *Device) GetSize() (uint64, error)
- func (d *Device) GetWholeDisk() (*Device, error)
- func (d *Device) IsCD() bool
- func (d *Device) IsCDNoMedia() bool
- func (d *Device) IsPrivateDeviceMapper() (bool, error)
- func (d *Device) IsReadOnly() (bool, error)
- func (d *Device) IsWholeDisk() (bool, error)
- func (d *Device) KernelPartitionAdd(no int, start, length uint64) error
- func (d *Device) KernelPartitionDelete(no int) error
- func (d *Device) KernelPartitionResize(no int, first, length uint64) error
- func (d *Device) Lock(exclusive bool) error
- func (d *Device) RetryLock(ctx context.Context, exclusive bool) error
- func (d *Device) RetryLockWithTimeout(ctx context.Context, exclusive bool, timeout time.Duration) error
- func (d *Device) TryLock(exclusive bool) error
- func (d *Device) Unlock() error
- func (d *Device) Wipe() (string, error)
- func (d *Device) WipeRange(start, length uint64) (string, error)
- type DeviceProperties
- type Option
- type Options
Constants ¶
const DefaultBlockSize = 512
DefaultBlockSize is the default block size in bytes.
const (
// FastWipeRange fast wipe block.
FastWipeRange = 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device wraps blockdevice operations.
func NewFromFile ¶
NewFromFile returns a new Device from the specified file.
func NewFromPath ¶
NewFromPath returns a new Device from the specified path.
func (*Device) FastWipe ¶
FastWipe the device contents.
This method is much faster than Wipe(), but it doesn't guarantee that device will be zeroed out completely.
func (*Device) GetKernelLastPartitionNum ¶
GetKernelLastPartitionNum returns the maximum partition number in the kernel.
func (*Device) GetProperties ¶
func (d *Device) GetProperties() (*DeviceProperties, error)
GetProperties returns the properties of the block device.
func (*Device) GetSectorSize ¶
GetSectorSize returns blockdevice sector size in bytes.
func (*Device) GetWholeDisk ¶
GetWholeDisk returns the whole disk for the blockdevice.
If the blockdevice is a whole disk, it returns itself. The returned block device should be closed.
func (*Device) IsCDNoMedia ¶
IsCDNoMedia returns true if the blockdevice is a CD-ROM device without media.
func (*Device) IsPrivateDeviceMapper ¶
IsPrivateDeviceMapper returns true if this is a private device-mapper device.
func (*Device) IsReadOnly ¶
IsReadOnly returns true if the blockdevice is read-only.
func (*Device) IsWholeDisk ¶
IsWholeDisk returns true if the blockdevice is a whole disk.
func (*Device) KernelPartitionAdd ¶
KernelPartitionAdd invokes the BLKPG_ADD_PARTITION ioctl.
func (*Device) KernelPartitionDelete ¶
KernelPartitionDelete invokes the BLKPG_DEL_PARTITION ioctl.
func (*Device) KernelPartitionResize ¶
KernelPartitionResize invokes the BLKPG_RESIZE_PARTITION ioctl.
func (*Device) RetryLockWithTimeout ¶
func (d *Device) RetryLockWithTimeout(ctx context.Context, exclusive bool, timeout time.Duration) error
RetryLockWithTimeout retries locking until the timeout.
type DeviceProperties ¶
type DeviceProperties struct { // Device name, as in 'sda'. DeviceName string // Model from /sys/block/*/device/model. Model string // Serial /sys/block/<dev>/device/serial. Serial string // Modalias /sys/block/<dev>/device/modalias. Modalias string // WWID /sys/block/<dev>/wwid. WWID string // UUID /sys/block/<dev>/uuid. // BusPath PCI bus path. BusPath string // SubSystem is the dest path of symlink /sys/block/<dev>/subsystem. SubSystem string // Transport of the device: SCSI, ata, ahci, nvme, etc. Transport string // Rotational is true if the device is a rotational disk. Rotational bool }
DeviceProperties contains the properties of a block device.