ltouwrap

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MPL-2.0 Imports: 9 Imported by: 0

README

ltouwrap

Simple Go wrapper for LTO tapes related cli utils (sg_logs, sg_read_attr and mt).

This library is under MPL v2 License.

⚠ Attention Please ⚠

This library has undergone extremely limited testing on Arch Linux with a virtual LTO-8 tape drive emulated by mhVTL.

If you plan to use it in production, proceed with caution.

You have been warned!

⚠ 请务必注意 ⚠

该库只在Arch Linux上使用mhVTL虚拟出的LTO-8虚拟磁带进行过极度有限的测试.

若您想将其用于生产, 请务必小心.

您已经被警告过了!

Documentation

Index

Constants

View Source
const ReadAttrMediumTypeDataCartridge uint8 = 0

In MAM attribute data, 0 means data cartridge, 1 means cleaning cartridge.

View Source
const UnknownCapacity int64 = -1

A magic number as "Capacity Unknown".

View Source
const UtilsDiscoverTimeout time.Duration = 1 * time.Second

Variables

View Source
var EnableLtoUtilsWrapperDebugMode bool = false

Debug Mode will show output of tape utils.

View Source
var ErrAttrParseFailed error = errors.New("failed to parse output of sg_read_attr")
View Source
var ErrCanNotGetMediumSN error = errors.New("can not get medium serial number")
View Source
var ErrCanNotGoToPrevFile error = errors.New("can not go to previous file")
View Source
var ErrCanNotParseAlternatePartitionMax error = errors.New("can not parse alternate partition maximum capacity")
View Source
var ErrCanNotParseAlternatePartitionRemaining error = errors.New("can not parse alternate partition remaining capacity")
View Source
var ErrCanNotParseMainPartitionMax error = errors.New("can not parse main partition maximum capacity")
View Source
var ErrCanNotParseMainPartitionRemaining error = errors.New("can not parse main partition remaining capacity")
View Source
var ErrCanNotParseSgReadAttrOutput error = errors.New("can not parse output of sg_read_attr")
View Source
var ErrCanNotRewind error = errors.New("can not rewind the tape")
View Source
var ErrCanNotStatTheDevice error = errors.New("can not stat specified device file")
View Source
var ErrDeviceCheckFailed error = errors.New("device check failed")
View Source
var ErrMtExecFailed error = errors.New("failed to get mt cmd output")
View Source
var ErrMtOutputParseFailed error = errors.New("can not parse output of mt")
View Source
var ErrNoDataCartridgeOrNotReady error = errors.New("no data cartridge or not ready yet")
View Source
var ErrNoMtDiscovered error = errors.New("can not find mt")
View Source
var ErrNoRewindRequired error = errors.New("a no rewind tape device is required")
View Source
var ErrNoSgLogsDiscovered error = errors.New("can not find sg_logs")
View Source
var ErrNoSgReadAttrDiscovered error = errors.New("can not find sg_read_attr")
View Source
var ErrSgLogsExecFailed error = errors.New("failed to get sg_logs cmd output")
View Source
var ErrSgReadAttrExecFailed error = errors.New("failed to get sg_read_attr cmd output")
View Source
var ErrSomeCapacityLogFieldsMissing error = errors.New("some capacity log fields missing")
View Source
var ErrSomeMtRelatedFieldsMissing error = errors.New("some mt related fields missing")
View Source
var ErrSomeSgRelatedFieldsMissing error = errors.New("some sg_* related fields missing")
View Source
var ErrUnsupportedPlatform error = errors.New("this os is not supported")

Functions

This section is empty.

Types

type LtoNoRewindTapeDrive

type LtoNoRewindTapeDrive struct {
	DeviceFile string
	SgLogs     string
	SgReadAttr string
	Mt         string
}

func NewLtoNoRewindTapeDrive

func NewLtoNoRewindTapeDrive(device string) (LtoNoRewindTapeDrive, error)

It will detect related utils automatically, if some detection failed, you might need to set the utils binary manually.

func (*LtoNoRewindTapeDrive) BSF

func (device *LtoNoRewindTapeDrive) BSF(count uint32, timeout time.Duration) error

func (*LtoNoRewindTapeDrive) BSFCtx

func (device *LtoNoRewindTapeDrive) BSFCtx(ctx context.Context, count uint32) error

func (*LtoNoRewindTapeDrive) BSFM

func (device *LtoNoRewindTapeDrive) BSFM(count uint32, timeout time.Duration) error

func (*LtoNoRewindTapeDrive) BSFMCtx

func (device *LtoNoRewindTapeDrive) BSFMCtx(ctx context.Context, count uint32) error

func (*LtoNoRewindTapeDrive) ChkDevice

func (device *LtoNoRewindTapeDrive) ChkDevice() error

func (*LtoNoRewindTapeDrive) CountFiles

func (device *LtoNoRewindTapeDrive) CountFiles(timeout time.Duration) (uint64, error)

This will cost a lot of time! Returned error will never be nil, it's the latest error.

After get the count, it'll rewind the tape for you.

func (*LtoNoRewindTapeDrive) Eject

func (device *LtoNoRewindTapeDrive) Eject(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) EjectCtx

func (device *LtoNoRewindTapeDrive) EjectCtx(ctx context.Context) error

func (*LtoNoRewindTapeDrive) Erase

func (device *LtoNoRewindTapeDrive) Erase(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) EraseCtx

func (device *LtoNoRewindTapeDrive) EraseCtx(ctx context.Context) error

func (*LtoNoRewindTapeDrive) ExecMtCmd

func (device *LtoNoRewindTapeDrive) ExecMtCmd(timeout time.Duration, cmd string, args ...uint32) ([]byte, error)

func (*LtoNoRewindTapeDrive) ExecMtCmdCtx

func (device *LtoNoRewindTapeDrive) ExecMtCmdCtx(ctx context.Context, cmd string, args ...uint32) ([]byte, error)

func (*LtoNoRewindTapeDrive) ExecSgReadAttr

func (device *LtoNoRewindTapeDrive) ExecSgReadAttr(id string) (string, error)

Use IDs like 0x0408 or 0408h.

func (*LtoNoRewindTapeDrive) FSF

func (device *LtoNoRewindTapeDrive) FSF(count uint32, timeout time.Duration) error

func (*LtoNoRewindTapeDrive) FSFCtx

func (device *LtoNoRewindTapeDrive) FSFCtx(ctx context.Context, count uint32) error

func (*LtoNoRewindTapeDrive) GetCapacityLog

func (device *LtoNoRewindTapeDrive) GetCapacityLog() (LtoTapeCapacityLog, error)

From the Tape Capacity log page (code is 31h).

func (*LtoNoRewindTapeDrive) GetCurFileNumber

func (device *LtoNoRewindTapeDrive) GetCurFileNumber() (uint64, error)

This let you know which file you are using, NOT total files count!

func (*LtoNoRewindTapeDrive) GetMediumSN

func (device *LtoNoRewindTapeDrive) GetMediumSN() (string, error)

From attribute ID 0401h.

func (*LtoNoRewindTapeDrive) HasDataCartridge

func (device *LtoNoRewindTapeDrive) HasDataCartridge() (bool, error)

Related attribute ID is 0408h.

func (*LtoNoRewindTapeDrive) NextFile

func (device *LtoNoRewindTapeDrive) NextFile(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) NextFileCtx

func (device *LtoNoRewindTapeDrive) NextFileCtx(ctx context.Context) error

func (*LtoNoRewindTapeDrive) PrevFile

func (device *LtoNoRewindTapeDrive) PrevFile(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) PrevFileCtx

func (device *LtoNoRewindTapeDrive) PrevFileCtx(ctx context.Context) error

func (*LtoNoRewindTapeDrive) Rewind

func (device *LtoNoRewindTapeDrive) Rewind(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) RewindCtx

func (device *LtoNoRewindTapeDrive) RewindCtx(ctx context.Context) error

func (*LtoNoRewindTapeDrive) TryReadAttr

func (device *LtoNoRewindTapeDrive) TryReadAttr() error

func (*LtoNoRewindTapeDrive) WEOF

func (device *LtoNoRewindTapeDrive) WEOF(timeout time.Duration) error

func (*LtoNoRewindTapeDrive) WEOFCtx

func (device *LtoNoRewindTapeDrive) WEOFCtx(ctx context.Context) error

type LtoTapeCapacityLog

type LtoTapeCapacityLog struct {
	MainPartitionRemaining      int64 // In MiB (1 MiB = 1048576 Bytes).
	AlternatePartitionRemaining int64 // In MiB (1 MiB = 1048576 Bytes).
	MainPartitionMax            int64 // In MiB (1 MiB = 1048576 Bytes).
	AlternatePartitionMax       int64 // In MiB (1 MiB = 1048576 Bytes).
}

Jump to

Keyboard shortcuts

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