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
- type Disk
- func (d *Disk) CreateFilesystem(spec FilesystemSpec) (filesystem.FileSystem, error)
- func (d *Disk) GetFilesystem(partition int) (filesystem.FileSystem, error)
- func (d *Disk) GetPartitionTable() (partition.Table, error)
- func (d *Disk) Partition(table partition.Table) error
- func (d *Disk) ReReadPartitionTable() error
- func (d *Disk) ReadPartitionContents(partition int, writer io.Writer) (int64, error)
- func (d *Disk) WritePartitionContents(partition int, reader io.Reader) (int64, error)
- type FilesystemSpec
- type Type
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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