lib

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package lib provides a Backend implementation that loads the smartmon wrapper library via purego (no CGO required). Build the wrapper library once with:

scripts/setup-lib-backend.sh

The script downloads the pre-built libsmartmon.a static library from https://github.com/dianlight/smartmontools-sdk releases and compiles the thin C++ wrapper (backends/lib/csrc/smartmon_c_api.cpp) into backends/lib/sdk/libsmartmon_go.{so,dylib}.

Then point the backend at it via SMARTMON_LIB_PATH or WithLibraryPath.

Package lib provides a Backend implementation that loads the smartmon wrapper library via purego (no CGO required). It is available on Linux and macOS.

Build the wrapper library once:

scripts/setup-lib-backend.sh

The script downloads the correct dianlight/smartmontools-sdk release for the current platform, installs the missing smartmon_config.h, and compiles the thin C++ wrapper into backends/lib/sdk/libsmartmon_go.{so,dylib}.

Library resolution order

  1. WithLibraryPath option — always takes precedence.
  2. SMARTMON_LIB_PATH environment variable. • File exists → used directly. A warning is logged if a library is also found in a different standard system directory. • File missing → warning logged; falls through to step 3.
  3. Standard system paths — dynamic-linker names (LD_LIBRARY_PATH / DYLD_LIBRARY_PATH / rpath) followed by well-known absolute paths such as /usr/local/lib and /opt/homebrew/lib.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtaSmartData

type AtaSmartData = smtypes.AtaSmartData

Shared type aliases reuse the module's SMART domain model in the lib backend.

type Backend

type Backend = smtypes.Backend

Shared interface aliases keep the lib backend decoupled from the root package.

type Device

type Device = smtypes.Device

Shared type aliases reuse the module's SMART domain model in the lib backend.

type DiscoveryResult

type DiscoveryResult = smtypes.DiscoveryResult

Shared type aliases reuse the module's SMART domain model in the lib backend.

type LibBackend

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

LibBackend implements Backend by loading the smartmon wrapper library via purego at runtime. No CGO is required. Build the wrapper once with:

scripts/setup-lib-backend.sh

The script downloads libsmartmon.a from github.com/dianlight/smartmontools-sdk releases and compiles the thin C++ wrapper into backends/lib/sdk/libsmartmon_go.{so,dylib}.

func New

func New(opts ...Option) (*LibBackend, error)

New creates a LibBackend by loading the smartmon wrapper library.

Library resolution order:

  1. WithLibraryPath option
  2. SMARTMON_LIB_PATH environment variable (if the file exists at that path). If SMARTMON_LIB_PATH is set but the file is absent a warning is logged and the search falls through to step 3. If SMARTMON_LIB_PATH resolves to a different directory than a library found in the system paths a warning is logged.
  3. Standard system library paths (dynamic linker names, then absolute paths).

func (*LibBackend) AbortSelfTest

func (b *LibBackend) AbortSelfTest(ctx context.Context, devicePath string) error

AbortSelfTest aborts a running SMART self-test on the given device.

func (*LibBackend) CheckHealth

func (b *LibBackend) CheckHealth(ctx context.Context, devicePath string) (bool, error)

CheckHealth returns true when the device passes its SMART overall-health assessment.

func (*LibBackend) Close

func (b *LibBackend) Close() error

Close calls smartmon_cleanup and unloads the shared library. It is safe to call Close more than once; subsequent calls are no-ops.

func (*LibBackend) DisableSMART

func (b *LibBackend) DisableSMART(ctx context.Context, devicePath string) error

DisableSMART disables SMART on the given ATA device.

func (*LibBackend) EnableSMART

func (b *LibBackend) EnableSMART(ctx context.Context, devicePath string) error

EnableSMART enables SMART on the given ATA device.

func (*LibBackend) GetAvailableSelfTests

func (b *LibBackend) GetAvailableSelfTests(ctx context.Context, devicePath string) (*SelfTestInfo, error)

GetAvailableSelfTests returns the self-test types available on the device and their estimated durations, parsed from the full SMART data.

func (*LibBackend) GetDeviceInfo

func (b *LibBackend) GetDeviceInfo(ctx context.Context, devicePath string) (map[string]any, error)

GetDeviceInfo returns raw key/value device information for the given device.

func (*LibBackend) GetSMARTInfo

func (b *LibBackend) GetSMARTInfo(ctx context.Context, devicePath string) (*SMARTInfo, error)

GetSMARTInfo returns comprehensive SMART information for the given device.

func (*LibBackend) Name

func (b *LibBackend) Name() string

Name returns the backend identifier.

func (*LibBackend) RunSelfTest

func (b *LibBackend) RunSelfTest(ctx context.Context, devicePath string, testType string) error

RunSelfTest starts a SMART self-test of the given type on the device. testType must be "short", "long", or "conveyance".

func (*LibBackend) ScanDevices

func (b *LibBackend) ScanDevices(ctx context.Context) ([]Device, error)

ScanDevices returns the list of storage devices visible to the wrapper library.

type LogAdapter

type LogAdapter = smtypes.LogAdapter

Shared interface aliases keep the lib backend decoupled from the root package.

type Option

type Option func(*LibBackend)

Option configures a LibBackend.

func WithLibraryPath

func WithLibraryPath(path string) Option

WithLibraryPath sets a custom path to the smartmon wrapper shared library. When not set, New checks SMARTMON_LIB_PATH, then defaultLibNames and defaultLibPaths.

func WithLogHandler

func WithLogHandler(logger LogAdapter) Option

WithLogHandler sets a custom logger adapter for the backend.

func WithSlogHandler

func WithSlogHandler(logger *slog.Logger) Option

WithSlogHandler sets a slog.Logger for the backend.

func WithTLogHandler

func WithTLogHandler(logger *tlog.Logger) Option

WithTLogHandler sets a tlog.Logger for the backend.

type SMARTInfo

type SMARTInfo = smtypes.SMARTInfo

Shared type aliases reuse the module's SMART domain model in the lib backend.

type SelfTestInfo

type SelfTestInfo = smtypes.SelfTestInfo

Shared type aliases reuse the module's SMART domain model in the lib backend.

type SmartStatus

type SmartStatus = smtypes.SmartStatus

Shared type aliases reuse the module's SMART domain model in the lib backend.

type SmartSupport

type SmartSupport = smtypes.SmartSupport

Shared type aliases reuse the module's SMART domain model in the lib backend.

Jump to

Keyboard shortcuts

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