loop

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package loop provides an interface to interacting with Linux loop devices.

A loop device exposes a regular file as if it were a block device.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFD

func ClearFD(fd int) error

ClearFD clears the loop device associated with file descriptor fd.

func ClearFile

func ClearFile(devicename string) error

ClearFile clears the fd association of the loop device "devicename".

func FindDevice

func FindDevice() (string, error)

FindDevice finds an unused loop device and returns its /dev/loopN path.

func GetFree

func GetFree(fd int) (int, error)

GetFree finds a free loop device /dev/loopN.

fd must be a loop control device.

It returns the number of the free loop device /dev/loopN.

func New

func New(source, target, fstype string, flags uintptr, data string) (mount.Mounter, error)

New initializes a Loop struct and allocates a loodevice to it.

source is the file to use as a loop block device. target is the directory the device should be mounted on.

func SetFD

func SetFD(lfd, ffd int) error

SetFD associates a loop device lfd with a regular file ffd.

func SetFile

func SetFile(devicename, filename string) error

SetFile associates loop device "devicename" with regular file "filename"

Types

type Loop

type Loop struct {
	// Dev is the loop device path.
	Dev string

	// Source is the regular file to use as a block device.
	Source string

	// Dir is the directory to mount the block device on.
	Dir string

	// FSType is the file system to use when mounting the block device.
	FSType string

	// Flags are flags to pass to mount(2).
	Flags uintptr

	// Data is the data to pass to mount(2).
	Data string

	// Mounted indicates whether the device has been mounted.
	Mounted bool
}

Loop represents a regular file exposed as a loop block device.

Loop implements mount.Mount.

func (*Loop) Mount

func (l *Loop) Mount() error

Mount mounts the provided source file, with type fstype, and flags and data options (which are usually 0 and ""), using the allocated loop device.

func (*Loop) Unmount

func (l *Loop) Unmount(flags int) error

Unmount unmounts and frees a loop. If it is mounted, it will try to unmount it. If the unmount fails, we try to free it anyway, after trying a more forceful unmount. We don't log errors, but we do return a concatentation of whatever errors occur.

Jump to

Keyboard shortcuts

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