Documentation ¶
Overview ¶
Package storage provides a unified method to access and modify to both fixed and removable disk storage. Implementations are kept consistent between platforms to permit testing through interfaces by consumers.
Index ¶
- type Device
- func (device *Device) DetectPartitions(mount bool) error
- func (device *Device) Dismount() error
- func (device *Device) Eject() error
- func (device *Device) FriendlyName() string
- func (device *Device) Identifier() string
- func (device *Device) Partition(label string) error
- func (device *Device) ProbeDevicePartitions() error
- func (device *Device) SelectPartition(minSize uint64, fs FileSystem) (*Partition, error)
- func (device *Device) Size() uint64
- func (device *Device) Wipe() error
- type FileSystem
- type Partition
- func (part *Partition) Contents() ([]string, error)
- func (part *Partition) Erase() error
- func (part *Partition) Format(label string) error
- func (part *Partition) Identifier() string
- func (part *Partition) Label() string
- func (part *Partition) Mount(base string) error
- func (part *Partition) MountPoint() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device describes a physical device that is currently attached to the system.
func New ¶
New takes a unique device ID (e.g. sda) and returns a pointer to a Device that describes the removable disk and its contents or an error.
func Search ¶
Search performs a device search based on the provided parameters and returns a slice of storage devices that meet the criteria. Parameters are not mandatory. For example, if no deviceID is passed, all deviceID's are considered for the search.
func (*Device) DetectPartitions ¶
DetectPartitions updates a device with known partition information on Linux.
func (*Device) Dismount ¶
Dismount enumerates all the mounted partitions on the device and unmounts them. It is typically used with a flag when safety after writes to disk are desired. Errors are only thrown when a mountpoint is found but cannot be unmounted.
func (*Device) FriendlyName ¶
FriendlyName returns a human-readable friendly name for the device using available make and model information.
func (*Device) Identifier ¶
Identifier returns a human-readable identifier for the device using the available device ID.
func (*Device) Partition ¶
Partition sets up a GPT-Style partition scheme, and creates a single FAT32 partition using the maximum amount of available space. Linux automatically assigns a GPT GUID (System or EFI) to the partition, meaning it does not automatically mount on Windows, however this is handled automatically in this library for Windows.
func (*Device) ProbeDevicePartitions ¶
ProbeDevicePartitions forces the operating system to reexamine the partition table information on Linux.
func (*Device) SelectPartition ¶
func (device *Device) SelectPartition(minSize uint64, fs FileSystem) (*Partition, error)
SelectPartition enumerates the partitions on a device and returns the first partition that matches the criteria. Size and type are valid criteria. A size of zero is treated as "any size". A blank type is treated as "any type". If both input parameters are set to any, the first available partition is returned, or an error if there are no avaialble partitions.
type FileSystem ¶
type FileSystem string
FileSystem provides standardized file system descriptions (e.g. FAT32, NTFS)
const ( // NTFS is the NTFS filesystem. NTFS FileSystem = "NTFS" // ExFAT is the ExFAT filesystem. ExFAT FileSystem = "exFAT" // FAT is the FAT filesystem. FAT FileSystem = "FAT" // FAT32 is the FAT32 filesystem. FAT32 FileSystem = "FAT32" // APFS is the Apple APFS filesystem. APFS FileSystem = "APFS" // UnknownFS is an unknown filesystem. UnknownFS FileSystem = "Unknown" // UnknownModel represents devices of unidentified models and makes. UnknownModel = "Unknown" )
type Partition ¶
type Partition struct {
// contains filtered or unexported fields
}
Partition describes a disk partition using platform-independent paths and terminology. Partitions are considered immutable. If a partition is changed it should be redetected to ensure data integrity.
func (*Partition) Erase ¶
Erase removes all files from a mounted partition. The erase operation is typically used when contents of a partition need to be refreshed, but a full reformat is not desirable, such as when a refresh is needed but the user is not running with elevated rights.
func (*Partition) Format ¶
Format formats the corresponding partition as vfat/FAT32 and sets the partition label.
func (*Partition) Identifier ¶
Identifier returns the identifier for the partition.
func (*Partition) Mount ¶
Mount reads the current mount point for the partition. If it is empty and the file system is readable, the device is mounted. If the device is already mounted, we simply do nothing and return.
func (*Partition) MountPoint ¶
MountPoint returns the mount point of the partition.