loop

package
v0.0.0-...-5fb8a3f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package loop implements an interface to configure Linux loop devices.

This package requires Linux 5.8 or higher because it uses the newer LOOP_CONFIGURE ioctl, which is better-behaved and twice as fast as the old approach. It doesn't support all of the cryptloop functionality as it has been superseded by dm-crypt and has known vulnerabilities. It also doesn't support on-the-fly reconfiguration of loop devices as this is rather unusual, works only under very specific circumstances and would make the API less clean.

Index

Constants

View Source
const (
	// Makes the loop device read-only even if the backing file is read-write.
	FlagReadOnly = 1
	// Unbinds the backing file as soon as the last user is gone. Useful for
	// unbinding after unmount.
	FlagAutoclear = 4
	// Enables kernel-side partition scanning on the loop device. Needed if you
	// want to access specific partitions on a loop device.
	FlagPartscan = 8
	// Enables direct IO for the loop device, bypassing caches and buffer
	// copying.
	FlagDirectIO = 16
)

All from @linux//include/uapi/linux:loop.h

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Block size of the loop device in bytes. Power of 2 between 512 and page
	// size.  Zero defaults to an reasonable block size.
	BlockSize uint32
	// Combination of flags from the Flag constants in this package.
	Flags uint32
	// Offset in bytes from the start of the file to the first byte of the
	// device. Usually zero.
	Offset uint64
	// Maximum size of the loop device in bytes. Zero defaults to the whole
	// file.
	SizeLimit uint64
}

type Device

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

Device represents a loop device.

func Create

func Create(f *os.File, c Config) (*Device, error)

Create creates a new loop device backed with the given file.

func Open

func Open(path string) (*Device, error)

Open opens a loop device at the given path. It returns an error if the path is not a loop device.

func (*Device) BackingFilePath

func (d *Device) BackingFilePath() (string, error)

BackingFilePath returns the path of the backing file

func (*Device) Close

func (d *Device) Close() error

Close closes all file descriptors open to the device. Does not remove the device itself or alter its configuration.

func (*Device) Dev

func (d *Device) Dev() (uint64, error)

Dev returns the Linux device ID of the loop device.

func (*Device) DevPath

func (d *Device) DevPath() (string, error)

DevPath returns the canonical path of this loop device in /dev.

func (*Device) RefreshSize

func (d *Device) RefreshSize() error

RefreshSize recalculates the size of the loop device based on the config and the size of the backing file.

func (*Device) Remove

func (d *Device) Remove() error

Remove removes the loop device.

Jump to

Keyboard shortcuts

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