disk

package
v0.0.0-...-5918e99 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package disk provides convenience functions for manipulating disks and I/O functions within libosdev.

Index

Constants

View Source
const (
	// UmountMaxTries is the maximum number of times to try unmounting before
	// resorting to lazy detaches
	UmountMaxTries = 3

	// UmountRetryTime is the length of time to wait in between umounts
	UmountRetryTime = 500 * time.Millisecond
)

Variables

This section is empty.

Functions

func CheckFS

func CheckFS(filename, filesystem string) error

CheckFS will try to check/fix the filesystems pointed to by filename using the helpers denoted by filesystem. This should only be used for internal image code on loopback devices!

func CopyFile

func CopyFile(source, dest string) error

CopyFile will copy the file and permissions to the new target

func CreateDeviceNode

func CreateDeviceNode(root string, node *DeviceNode) error

CreateDeviceNode will create the essential nodes in a chroot path

func CreateSparseFile

func CreateSparseFile(filename string, nMegabytes int) error

CreateSparseFile will create a new sparse file with the given filename and size in nMegabytes/

This is highly dependent on the underlying filesystem at the directory where the file is to be created, making use of the syscall ftruncate.

func CreateSquashfs

func CreateSquashfs(path, outputFile string, compressionType CompressionType) error

CreateSquashfs will create a new squashfs filesystem image at the given outputFile path, containing the tree found at path, using compressionType (gzip or xz).

func FormatAs

func FormatAs(filename, filesystem string) error

FormatAs will format the given path with the filesystem specified. Note: You should only use this with image paths, it's dangerous!

func GetSquashfsArgs

func GetSquashfsArgs(compressionType CompressionType) ([]string, error)

GetSquashfsArgs returns the compression arg set for a given compression type

Types

type CompressionType

type CompressionType string

CompressionType is the possible compression type to be used with a LiveOS image build

const (
	// CompressionGzip will compress the squashfs with gzip
	CompressionGzip CompressionType = "gzip"

	// CompressionXZ will compress the squashfs using xz
	CompressionXZ CompressionType = "xz"
)

type DeviceNode

type DeviceNode struct {
	Mode  string // Mode to create the device node in
	Major uint32 // Major ID
	Minor uint32 // Minor ID
	Path  string // Path within a chroot (no / prefix)
}

DeviceNode represents a /dev/ node to be created in chroots

var (
	// DevNodeRandom is /dev/random
	DevNodeRandom *DeviceNode

	// DevNodeURandom is /dev/urandom
	DevNodeURandom *DeviceNode
)

type FilesystemCheckFunc

type FilesystemCheckFunc func(filename string) error

A FilesystemCheckFunc is a function prototype for performing filesystem checks, i.e. a rootfs.img after unmounting

type FilesystemFormatFunc

type FilesystemFormatFunc func(filename string) error

FilesystemFormatFunc is the prototype for functions that format filesystems to ensure we can use dedicated functions that can handle filesystem paths correctly (i.e. spaces)

type LenSort

type LenSort []string

LenSort is to enable reverse length sorting

func (LenSort) Len

func (l LenSort) Len() int

Len returns the length of the string slice

func (LenSort) Less

func (l LenSort) Less(a, b int) bool

Less determines if a is less than b. This is deliberately negated

func (LenSort) Swap

func (l LenSort) Swap(a, b int)

Swap will swap two elements by index in the string slice

type MountEntry

type MountEntry struct {
	SourcePath string // The source of the mount
	MountPoint string // The destination mount point
}

A MountEntry is tracked by the MountManager to enable proper cleanup takes place

func (*MountEntry) Umount

func (m *MountEntry) Umount() error

Umount will attempt to unmount the given path

func (*MountEntry) UmountForce

func (m *MountEntry) UmountForce() error

UmountForce will attempt to forcibly detach the mountpoint

func (*MountEntry) UmountLazy

func (m *MountEntry) UmountLazy() error

UmountLazy will attempt a lazy detach of the node

func (*MountEntry) UmountSync

func (m *MountEntry) UmountSync() error

UmountSync will attempt everything possible to umount itself

type MountManager

type MountManager struct {
	// contains filtered or unexported fields
}

A MountManager is used to mount and unmount filesystems, and to track them so that they are all properly torn down.

It is relied upon to provide bulletproof unmounting in instances of failure, so that in every event the mountpoints are always taken back down, ensuring no usability issues for the USpin user.

func GetMountManager

func GetMountManager() *MountManager

GetMountManager will return the global mount manager

func (*MountManager) BindMount

func (m *MountManager) BindMount(sourcepath, destpath string, options ...string) error

BindMount will attempt to mount the given sourcepath at the destpath with a binding

func (*MountManager) Mount

func (m *MountManager) Mount(sourcepath, destpath, filesystem string, options ...string) error

Mount will attempt to mount the given sourcepath at the destpath

func (*MountManager) RemountReadonly

func (m *MountManager) RemountReadonly(destpath string) error

RemountReadonly allows forcing a bindmount to be read-only, because for whatever reason, to this day, Linux _still_ ignores "-o ro" when issuing a bind mount.

func (*MountManager) SetPrivateMounts

func (m *MountManager) SetPrivateMounts(b bool)

SetPrivateMounts will instruct MountManager to use --make-private whenever mounting a new device.

func (*MountManager) Unmount

func (m *MountManager) Unmount(mountpoint string) error

Unmount will attempt to unmount the given path

func (*MountManager) UnmountAll

func (m *MountManager) UnmountAll()

UnmountAll will attempt to unmount all registered mountpoints

Jump to

Keyboard shortcuts

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