disk

package
v1.1.2-0...-3c71667 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package disk provides utilities for working directly with a disk

Most of the provided functions are intelligent wrappers around implementations of github.com/diskfs/go-diskfs/partition and github.com/diskfs/go-diskfs/filesystem

Index

Constants

View Source
const (
	BLKRRPART = 0x125f
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Disk

type Disk struct {
	File              *os.File
	Info              os.FileInfo
	Type              Type
	Size              int64
	LogicalBlocksize  int64
	PhysicalBlocksize int64
	Table             partition.Table
	Writable          bool
	DefaultBlocks     bool
}

Disk is a reference to a single disk block device or image that has been Create() or Open()

func (*Disk) CreateFilesystem

func (d *Disk) CreateFilesystem(spec FilesystemSpec) (filesystem.FileSystem, error)

CreateFilesystem creates a filesystem on a disk image, the equivalent of mkfs.

Required:

  • desired partition number, or 0 to create the filesystem on the entire block device or disk image,
  • the filesystem type from github.com/diskfs/go-diskfs/filesystem

Optional:

  • volume label for those filesystems that support it; under Linux this shows in '/dev/disks/by-label/<label>'

if successful, returns a filesystem-implementing structure for the given filesystem type

returns error if there was an error creating the filesystem, or the partition table is invalid and did not request the entire disk.

func (*Disk) GetFilesystem

func (d *Disk) GetFilesystem(partition int) (filesystem.FileSystem, error)

GetFilesystem gets the filesystem that already exists on a disk image

pass the desired partition number, or 0 to create the filesystem on the entire block device / disk image,

if successful, returns a filesystem-implementing structure for the given filesystem type

returns error if there was an error reading the filesystem, or the partition table is invalid and did not request the entire disk.

func (*Disk) GetPartitionTable

func (d *Disk) GetPartitionTable() (partition.Table, error)

GetPartitionTable retrieves a PartitionTable for a Disk

returns an error if the Disk is invalid or does not exist, or the partition table is unknown

func (*Disk) Partition

func (d *Disk) Partition(table partition.Table) error

Partition applies a partition.Table implementation to a Disk

The Table can have zero, one or more Partitions, each of which is unique to its implementation. E.g. MBR partitions in mbr.Table look different from GPT partitions in gpt.Table

Actual writing of the table is delegated to the individual implementation

func (*Disk) ReReadPartitionTable

func (d *Disk) ReReadPartitionTable() error

ReReadPartitionTable forces the kernel to re-read the partition table on the disk.

It is done via an ioctl call with request as BLKRRPART.

func (*Disk) ReadPartitionContents

func (d *Disk) ReadPartitionContents(partition int, writer io.Writer) (int64, error)

ReadPartitionContents reads the contents of a partition to an io.Writer

if successful, returns the number of bytes read

returns an error if there was an error reading from the disk, writing to the writer, the table is invalid, or the partition is invalid

func (*Disk) WritePartitionContents

func (d *Disk) WritePartitionContents(partition int, reader io.Reader) (int64, error)

WritePartitionContents writes the contents of an io.Reader to a given partition

if successful, returns the number of bytes written

returns an error if there was an error writing to the disk, reading from the reader, the table is invalid, or the partition is invalid

type FilesystemSpec

type FilesystemSpec struct {
	Partition   int
	FSType      filesystem.Type
	VolumeLabel string
	WorkDir     string
}

FilesystemSpec represents the specification of a filesystem to be created

type Type

type Type int

Type represents the type of disk this is

const (
	// File is a file-based disk image
	File Type = iota
	// Device is an OS-managed block device
	Device
)

Jump to

Keyboard shortcuts

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