loop

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: BSD-3-Clause Imports: 4 Imported by: 25

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. The _LOOP_CTL_GET_FREE does not follow the rules. Values of 0 or greater are the number of the device; less than zero is an error. So you can not use unix.IoctlGetInt as it assumes the return value is stored in a pointer in the normal style. Yuck.

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

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

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

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

Loop implements mount.Mounter.

func New

func New(source, fstype string, data string) (*Loop, error)

New initializes a Loop struct and allocates a loop device to it.

source is the file to use as a loop block device. fstype the file system name. data is the data argument to the mount(2) syscall.

func (*Loop) DevName

func (l *Loop) DevName() string

DevName implements mount.Mounter.

func (*Loop) Free

func (l *Loop) Free() error

Free frees the loop device.

All mount points must have been unmounted prior to calling this.

func (*Loop) Mount

func (l *Loop) Mount(path string, flags uintptr, opts ...func() error) (*mount.MountPoint, 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.

Jump to

Keyboard shortcuts

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