Documentation ¶
Index ¶
- Variables
- func GenericZero(b BlockDev, startByte, endByte int64) error
- type BlockDev
- type Device
- func (d *Device) BlockCount() int64
- func (d *Device) BlockSize() int64
- func (d *Device) Close() error
- func (d *Device) Discard(startByte int64, endByte int64) error
- func (d *Device) OptimalBlockSize() int64
- func (d *Device) ReadAt(p []byte, off int64) (n int, err error)
- func (d *Device) RefreshPartitionTable() error
- func (d *Device) ResizePartition(partitionNo int32, startByte, lengthBytes int64) error
- func (d *Device) Sync() error
- func (d *Device) WriteAt(p []byte, off int64) (n int, err error)
- func (d *Device) Zero(startByte int64, endByte int64) error
- type File
- func (d *File) BlockCount() int64
- func (d *File) BlockSize() int64
- func (d *File) Close() error
- func (d *File) Discard(startByte int64, endByte int64) error
- func (d *File) OptimalBlockSize() int64
- func (d *File) ReadAt(p []byte, off int64) (n int, err error)
- func (d *File) Sync() error
- func (d *File) WriteAt(p []byte, off int64) (n int, err error)
- func (d *File) Zero(startByte int64, endByte int64) error
- type Memory
- func (m *Memory) BlockCount() int64
- func (m *Memory) BlockSize() int64
- func (m *Memory) Discard(startByte, endByte int64) error
- func (m *Memory) OptimalBlockSize() int64
- func (m *Memory) ReadAt(p []byte, off int64) (n int, err error)
- func (m *Memory) Sync() error
- func (m *Memory) WriteAt(p []byte, off int64) (n int, err error)
- func (m *Memory) Zero(startByte, endByte int64) error
- type ReadWriteSeeker
- type Section
- func (s *Section) BlockCount() int64
- func (s *Section) BlockSize() int64
- func (s *Section) Discard(startByte, endByte int64) error
- func (s *Section) OptimalBlockSize() int64
- func (s *Section) ReadAt(p []byte, off int64) (n int, err error)
- func (s *Section) Sync() error
- func (s *Section) WriteAt(p []byte, off int64) (n int, err error)
- func (s *Section) Zero(startByte, endByte int64) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotBlockDevice = errors.New("not a block device")
var ErrOutOfBounds = errors.New("write out of bounds")
Functions ¶
func GenericZero ¶
GenericZero implements software-based zeroing. This can be used to implement Zero when no acceleration is available or desired.
Types ¶
type BlockDev ¶
type BlockDev interface { io.ReaderAt io.WriterAt // BlockCount returns the number of blocks on the block device or -1 if it // is an image with an undefined size. BlockCount() int64 // BlockSize returns the block size of the block device in bytes. This must // be a power of two and is commonly (but not always) either 512 or 4096. BlockSize() int64 // OptimalBlockSize returns the optimal block size in bytes for aligning // to as well as issuing I/O. IO operations with block sizes below this // one might incur read-write overhead. This is the larger of the physical // block size and a device-reported value if available. OptimalBlockSize() int64 // Discard discards a continuous set of blocks. Discarding means the // underlying device gets notified that the data in these blocks is no // longer needed. This can improve performance of the device device (as it // no longer needs to preserve the unused data) as well as bulk erase // operations. This command is advisory and not all implementations support // it. The contents of discarded blocks are implementation-defined. Discard(startByte int64, endByte int64) error // Zero zeroes a continouous set of blocks. On certain implementations this // can be significantly faster than just calling Write with zeroes. Zero(startByte, endByte int64) error // Sync commits the current contents to stable storage. Sync() error }
BlockDev represents a generic block device made up of equally-sized blocks. All offsets and intervals are expressed in bytes and must be aligned to BlockSize and are recommended to be aligned to OptimalBlockSize if feasible. Unless stated otherwise, intervals are inclusive-exclusive, i.e. the start byte is included but the end byte is not.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func FromFileHandle ¶
FromFileHandle creates a blockdev from a device handle. The device handle is not duplicated, closing the returned Device will close it. If the handle is not a block device, i.e does not implement block device ioctls, an error is returned.
func (*Device) BlockCount ¶
func (*Device) OptimalBlockSize ¶
func (*Device) RefreshPartitionTable ¶
RefreshPartitionTable refreshes the kernel's view of the partition table after changes made from userspace.
func (*Device) ResizePartition ¶
ResizePartition updates the start and length of one partition in the kernel. This can be used as an alternative to RefreshPartitionTable, which cannot be used if any partition on this device is currently mounted.
type File ¶
type File struct {
// contains filtered or unexported fields
}
func (*File) BlockCount ¶
func (*File) OptimalBlockSize ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a memory-backed implementation of BlockDev. It is optimal for testing and temporary use, as it is fast and platform-independent.
func MustNewMemory ¶
MustNewMemory works exactly like NewMemory, but panics when NewMemory would return an error. Intended for use in tests.
func (*Memory) BlockCount ¶
func (*Memory) OptimalBlockSize ¶
type ReadWriteSeeker ¶
type ReadWriteSeeker struct {
// contains filtered or unexported fields
}
ReadWriteSeeker provides an adapter implementing ReadWriteSeeker on top of a blockdev.
func NewRWS ¶
func NewRWS(b BlockDev) *ReadWriteSeeker
type Section ¶
type Section struct {
// contains filtered or unexported fields
}
Section implements BlockDev on a slice of another BlockDev given a startBlock and endBlock.
func NewSection ¶
NewSection returns a new Section, implementing BlockDev over that subset of blocks. The interval is inclusive-exclusive.