Documentation ¶
Overview ¶
Package disk provides convenience functions for manipulating disks and I/O functions within libosdev.
Index ¶
- Constants
- func CheckFS(filename, filesystem string) error
- func CopyFile(source, dest string) error
- func CreateDeviceNode(root string, node *DeviceNode) error
- func CreateSparseFile(filename string, nMegabytes int) error
- func CreateSquashfs(path, outputFile string, compressionType CompressionType) error
- func FormatAs(filename, filesystem string) error
- func GetSquashfsArgs(compressionType CompressionType) ([]string, error)
- type CompressionType
- type DeviceNode
- type FilesystemCheckFunc
- type FilesystemFormatFunc
- type LenSort
- type MountEntry
- type MountManager
- func (m *MountManager) BindMount(sourcepath, destpath string, options ...string) error
- func (m *MountManager) Mount(sourcepath, destpath, filesystem string, options ...string) error
- func (m *MountManager) RemountReadonly(destpath string) error
- func (m *MountManager) SetPrivateMounts(b bool)
- func (m *MountManager) Unmount(mountpoint string) error
- func (m *MountManager) UnmountAll()
Constants ¶
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 ¶
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 CreateDeviceNode ¶
func CreateDeviceNode(root string, node *DeviceNode) error
CreateDeviceNode will create the essential nodes in a chroot path
func CreateSparseFile ¶
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 ¶
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 ¶
A FilesystemCheckFunc is a function prototype for performing filesystem checks, i.e. a rootfs.img after unmounting
type FilesystemFormatFunc ¶
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
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