blockdevice

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MPL-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package blockdevice provides a library for working with block devices.

Index

Constants

View Source
const (
	BLKDISCARD       = 4727
	BLKDISCARDZEROES = 4732
	BLKSECDISCARD    = 4733
	BLKZEROOUT       = 4735
)

Linux headers constants.

Hardcoded here to avoid CGo dependency.

View Source
const (
	// FastWipeRange fast wipe block.
	FastWipeRange = 1024 * 1024
	// ReadonlyMode readonly mode.
	ReadonlyMode = unix.O_CLOEXEC | os.O_RDONLY
	// DefaultMode read write.
	DefaultMode = unix.O_CLOEXEC | os.O_RDWR
)

Variables

View Source
var ErrMissingPartitionTable = errors.New("missing partition table")

ErrMissingPartitionTable indicates that the block device does not have a partition table.

Functions

func IsOutOfSpaceError

func IsOutOfSpaceError(err error) bool

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

func (*BlockDevice) WipeRange

func (bd *BlockDevice) WipeRange(start, length uint64) (string, error)

WipeRange the blockdevice [start, start+length).

type Option

type Option func(*Options)

Option is the functional option func.

func WithExclusiveLock

func WithExclusiveLock(o bool) Option

WithExclusiveLock locks the blockdevice for exclusive access using flock().

func WithMode

func WithMode(value int) Option

WithMode opens blockdevice in a specific mode.

func WithNewGPT

func WithNewGPT(o bool) Option

WithNewGPT opens the blockdevice with a new GPT.

type Options

type Options struct {
	CreateGPT     bool
	ExclusiveLock bool
	Mode          int
}

Options is the functional options struct.

func NewDefaultOptions

func NewDefaultOptions(setters ...Option) *Options

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.

Jump to

Keyboard shortcuts

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