device

package
v0.0.0-...-acfa6a3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	// String gets the full path to the device
	//
	// on Linux:
	// /dev/sda1
	String() string

	// MountpointPath gets the path to mount the device
	//
	// on Linux:
	// /tmp/dev-sda1
	MountpointPath() string

	// Mounts the device to the system for read and write creating a
	// directory to mount it to.
	Mount() error

	// Unmounts the device from the system and cleans up any temporary
	// directories. Unmount should keep attempting to unmount while
	// "device or resource is busy".
	Unmount() error
}

Device Usb interface requires that a Device on a platform can be used as a backup device.

type LinuxDevice

type LinuxDevice struct {
	Name       string
	Ro         bool
	Mountpoint string
	Type       string
	Children   []*LinuxDevice
}

LinuxDevice A Device given by `lsblk` on Linux

func Lsblk

func Lsblk() ([]*LinuxDevice, error)

Lsblk lists devices using `lsblk` filtering out mounted, Read only, and crypt devices

`TYPE` must be "part"

Converts

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 232.9G 0 disk └─sda1 8:1 0 232.9G 0 part nvme0n1 259:0 0 238.5G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot/efi └─nvme0n1p2 259:2 0 237.5G 0 part

└─root            254:0    0 237.5G  0 crypt
  ├─Volumes-swap  254:1    0     8G  0 lvm   [SWAP]
  ├─Volumes-nixos 254:2    0    60G  0 lvm   /
  └─Volumes-home  254:3    0 169.5G  0 lvm   /home

To

[ sda1 ]

func (*LinuxDevice) Mount

func (d *LinuxDevice) Mount() error

Mount execs the "mount" command on Linux, differing from golang.org/x/sys/unix because mount (as seen in `$ man mount 8`) guesses the filesystem and other things about the device.

func (*LinuxDevice) MountpointPath

func (d *LinuxDevice) MountpointPath() string

MountpointPath mounts a device to `/tmp/` on Unix of the name of

`/tmp/dev-Name`

func (*LinuxDevice) String

func (d *LinuxDevice) String() string

String returns the full path to the device

Effectively `/dev/Name`

func (*LinuxDevice) Unmount

func (d *LinuxDevice) Unmount() error

Unmount uses the golang.org/x/sys/unix Unmount in order to unmount and cleanup

Jump to

Keyboard shortcuts

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