losetup

package module
v0.0.0-...-2a14873 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 4 Imported by: 6

README

go-losetup

A losetup implementation for go-lang

how to get it

go get github.com/freddierice/go-losetup

example usage

// attach a raw file to a loop device
dev, err := losetup.Attach("rawfile.img", 0, false)
if err != nil {
	// error checking
}

fmt.Printf("attached rawfile.img to %v\n", dev.Path())

err := dev.Detach()
if err != nil {
	// error checking
}

Documentation

Index

Constants

View Source
const (
	// general constants
	NameSize = 64
	KeySize  = 32
	Major    = 7

	// paths
	LoopControlPath = "/dev/loop-control"

	// loop flags
	FlagsReadOnly  = 1
	FlagsAutoClear = 4
	FlagsPartScan  = 8
	FlagsDirectIO  = 16

	// loop filter types
	CryptNone      = 0
	CryptXor       = 1
	CryptDes       = 2
	CryptFish2     = 3
	CryptBlow      = 4
	CryptCast128   = 5
	CryptIdea      = 6
	CryptDummy     = 9
	CryptSkipjack  = 10
	CryptCryptoApi = 18
	MaxCrypt       = 20

	// ioctl commands
	SetFd       = 0x4C00
	ClrFd       = 0x4C01
	SetStatus   = 0x4C02
	GetStatus   = 0x4C03
	SetStatus64 = 0x4C04
	GetStatus64 = 0x4C05
	ChangeFd    = 0x4C06
	SetCapacity = 0x4C07
	SetDirectIO = 0x4C08

	CtlAdd     = 0x4C80
	CtlRemove  = 0x4C81
	CtlGetFree = 0x4C82
)
View Source
const DeviceFormatString = "/dev/loop%d"

DeviceFormatString holds the format of loopback devices

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

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

Device represents a loop device /dev/loop#

func Attach

func Attach(backingFile string, offset uint64, ro bool) (Device, error)

Attach attaches backingFile to the loopback device starting at offset. If ro is true, then the file is attached read only.

func GetFree

func GetFree() (Device, error)

GetFree searches for the first free loopback device. If it cannot find one, it will attempt to create one. If anything fails, GetFree will return an error.

func New

func New(number uint64, flags int) Device

New creates a reference to a specific loop device, if you know which one you want to reference.

func (Device) Add

func (device Device) Add() error

Add will add a loopback device if it does not exist already.

func (Device) Detach

func (device Device) Detach() error

Detach removes the file backing the device.

func (Device) GetInfo

func (device Device) GetInfo() (Info, error)

GetInfo returns information about a loop device

func (Device) Path

func (device Device) Path() string

Path returns the path to the loopback device

func (Device) Remove

func (device Device) Remove() error

Remove will remove a loopback device if it is not busy.

func (Device) SetInfo

func (device Device) SetInfo(info Info) error

SetInfo sets options in the loop device.

func (Device) String

func (device Device) String() string

String implements the Stringer interface for Device

type Info

type Info struct {
	Device         uint64
	INode          uint64
	RDevice        uint64
	Offset         uint64
	SizeLimit      uint64
	Number         uint32
	EncryptType    uint32
	EncryptKeySize uint32
	Flags          uint32
	FileName       [NameSize]byte
	CryptName      [NameSize]byte
	EncryptKey     [KeySize]byte
	Init           [2]uint64
}

Info is a datastructure that holds relevant information about a file backed loopback device.

func (Info) String

func (info Info) String() string

String implements the Stringer interface for Info

Jump to

Keyboard shortcuts

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