Documentation ¶
Overview ¶
Package blockdevice provides a library for working with block devices.
Index ¶
- Constants
- Variables
- func IsOutOfSpaceError(err error) bool
- type BlockDevice
- func (bd *BlockDevice) Close() error
- func (bd *BlockDevice) Device() *os.File
- func (bd *BlockDevice) FastWipe() error
- func (bd *BlockDevice) GetPartition(label string) (*gpt.Partition, error)
- func (bd *BlockDevice) OpenPartition(label string, setters ...Option) (*BlockDevice, error)
- func (bd *BlockDevice) PartPath(label string) (string, error)
- func (bd *BlockDevice) PartitionTable() (*gpt.GPT, error)
- func (bd *BlockDevice) RereadPartitionTable() error
- func (bd *BlockDevice) Reset() error
- func (bd *BlockDevice) Size() (uint64, error)
- func (bd *BlockDevice) Wipe() (string, error)
- func (bd *BlockDevice) WipeRange(start, length uint64) (string, error)
- type Option
- type Options
- type OutOfSpaceError
Constants ¶
const ( BLKDISCARD = 4727 BLKDISCARDZEROES = 4732 BLKSECDISCARD = 4733 BLKZEROOUT = 4735 )
Linux headers constants.
Hardcoded here to avoid CGo dependency.
Variables ¶
var ErrMissingPartitionTable = errors.New("missing partition table")
ErrMissingPartitionTable indicates that the block device does not have a partition table.
Functions ¶
func IsOutOfSpaceError ¶
IsOutOfSpaceError checks if provided error is 'out of space'.
Types ¶
type BlockDevice ¶
type BlockDevice struct {
// contains filtered or unexported fields
}
BlockDevice represents a block device.
func Open ¶
func Open(devname string, setters ...Option) (_ *BlockDevice, rerr error)
Open initializes and returns a block device. TODO(andrewrynhard): Use BLKGETSIZE ioctl to get the size.
func (*BlockDevice) Close ¶
func (bd *BlockDevice) Close() error
Close closes the block devices's open file.
func (*BlockDevice) Device ¶
func (bd *BlockDevice) Device() *os.File
Device returns the backing file for the block device.
func (*BlockDevice) FastWipe ¶
func (bd *BlockDevice) FastWipe() error
FastWipe the blockdevice contents.
This method is much faster than Wipe(), but it doesn't guarantee that device will be zeroed out completely.
func (*BlockDevice) GetPartition ¶
func (bd *BlockDevice) GetPartition(label string) (*gpt.Partition, error)
GetPartition returns partition by label if found.
func (*BlockDevice) OpenPartition ¶
func (bd *BlockDevice) OpenPartition(label string, setters ...Option) (*BlockDevice, error)
OpenPartition opens another blockdevice using a partition of this block device.
func (*BlockDevice) PartPath ¶
func (bd *BlockDevice) PartPath(label string) (string, error)
PartPath returns partition path by label, verifies that partition exists.
func (*BlockDevice) PartitionTable ¶
func (bd *BlockDevice) PartitionTable() (*gpt.GPT, error)
PartitionTable returns the block device partition table.
func (*BlockDevice) RereadPartitionTable ¶
func (bd *BlockDevice) RereadPartitionTable() error
RereadPartitionTable invokes the BLKRRPART ioctl to have the kernel read the partition table.
NB: Rereading the partition table requires that all partitions be unmounted or it will fail with EBUSY.
func (*BlockDevice) Reset ¶
func (bd *BlockDevice) Reset() error
Reset will reset a block device given a device name. Simply deletes partition table on device.
func (*BlockDevice) Size ¶
func (bd *BlockDevice) Size() (uint64, error)
Size returns the size of the block device in bytes.
func (*BlockDevice) Wipe ¶
func (bd *BlockDevice) Wipe() (string, error)
Wipe the blockdevice contents.
In order of availability this tries to perform the following:
- secure discard (secure erase)
- discard with zeros
- zero out via ioctl
- zero out from userland
type Option ¶
type Option func(*Options)
Option is the functional option func.
func WithExclusiveLock ¶
WithExclusiveLock locks the blockdevice for exclusive access using flock().
type Options ¶
Options is the functional options struct.
func NewDefaultOptions ¶
NewDefaultOptions initializes a Options struct with default values.
type OutOfSpaceError ¶
type OutOfSpaceError interface {
OutOfSpaceError()
}
OutOfSpaceError is implemented by out of space errors.
Directories ¶
Path | Synopsis |
---|---|
Package blkpg provices functions for working with the BLKPG family of iotctls.
|
Package blkpg provices functions for working with the BLKPG family of iotctls. |
cmd
|
|
wipe
main is the entrypoint for the wipe command.
|
main is the entrypoint for the wipe command. |
Package encryption provides abstraction level for various disk encryption methods.
|
Package encryption provides abstraction level for various disk encryption methods. |
luks
Package luks provides a way to call LUKS2 cryptsetup.
|
Package luks provides a way to call LUKS2 cryptsetup. |
Package endianness provides functions for translating the endianness of binary data.
|
Package endianness provides functions for translating the endianness of binary data. |
Package filesystem provides functions for working with common filesystems.
|
Package filesystem provides functions for working with common filesystems. |
ext4
Package ext4 provides functions for working with the ext filesystems.
|
Package ext4 provides functions for working with the ext filesystems. |
iso9660
Package iso9660 provides functions for working with the ISO9660 filesystem.
|
Package iso9660 provides functions for working with the ISO9660 filesystem. |
luks
Package luks provides functions for working with the LUKS2 encrypted filesystem.
|
Package luks provides functions for working with the LUKS2 encrypted filesystem. |
msdos
Package msdos provides functions for working with the FAT12/16 filesystems.
|
Package msdos provides functions for working with the FAT12/16 filesystems. |
vfat
Package vfat provides functions for working with the VFAT filesystem.
|
Package vfat provides functions for working with the VFAT filesystem. |
xfs
Package xfs provides functions for working with the XFS filesystem.
|
Package xfs provides functions for working with the XFS filesystem. |
Package lba provides a library for working with Logical Block Addresses.
|
Package lba provides a library for working with Logical Block Addresses. |
Package loopback provides support for disk loopback devices (/dev/loopN).
|
Package loopback provides support for disk loopback devices (/dev/loopN). |
Package partition provides a library for working with partition tables.
|
Package partition provides a library for working with partition tables. |
gpt
Package gpt provides a library for working with GPT partitions.
|
Package gpt provides a library for working with GPT partitions. |
Package probe provides functions for probing block devices for things such as filesystems, and partions.
|
Package probe provides functions for probing block devices for things such as filesystems, and partions. |
Package serde provides functions for serializing and deserializing binary data.
|
Package serde provides functions for serializing and deserializing binary data. |
Package test contains common test code for all tests in the package.
|
Package test contains common test code for all tests in the package. |
Package util provides helper utilities for parsing blockdevice and partition paths.
|
Package util provides helper utilities for parsing blockdevice and partition paths. |
disk
Package disk provides utility method for disk listing and searching using /sys/block data.
|
Package disk provides utility method for disk listing and searching using /sys/block data. |