blockdevice

package
v0.1.1-0...-42241d0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

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 = 1024 * 1024
)

Fast wipe parameters.

Variables

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

ErrMissingPartitionTable indicates that the 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) (bd *BlockDevice, err 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) OpenPartition

func (bd *BlockDevice) OpenPartition(label string) (*BlockDevice, error)

OpenPartition opens another blockdevice using a partition of this block device.

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 WithNewGPT

func WithNewGPT(o bool) Option

WithNewGPT opens the blockdevice with a new GPT.

type Options

type Options struct {
	CreateGPT bool
}

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 the the BLKPG family of iotctls.
Package blkpg provices functions for working the the BLKPG family of iotctls.
cmd
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.
iso9660
Package iso9660 provides functions for working with the ISO9660 filesystem.
Package iso9660 provides functions for working with the ISO9660 filesystem.
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.

Jump to

Keyboard shortcuts

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