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 ¶
- WithLibraryPath option — always takes precedence.
- 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.
- 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 ¶
- type AtaSmartData
- type Backend
- type Device
- type DiscoveryResult
- type LibBackend
- func (b *LibBackend) AbortSelfTest(ctx context.Context, devicePath string) error
- func (b *LibBackend) CheckHealth(ctx context.Context, devicePath string) (bool, error)
- func (b *LibBackend) Close() error
- func (b *LibBackend) DisableSMART(ctx context.Context, devicePath string) error
- func (b *LibBackend) EnableSMART(ctx context.Context, devicePath string) error
- func (b *LibBackend) GetAvailableSelfTests(ctx context.Context, devicePath string) (*SelfTestInfo, error)
- func (b *LibBackend) GetDeviceInfo(ctx context.Context, devicePath string) (map[string]any, error)
- func (b *LibBackend) GetSMARTInfo(ctx context.Context, devicePath string) (*SMARTInfo, error)
- func (b *LibBackend) Name() string
- func (b *LibBackend) RunSelfTest(ctx context.Context, devicePath string, testType string) error
- func (b *LibBackend) ScanDevices(ctx context.Context) ([]Device, error)
- type LogAdapter
- type Option
- type SMARTInfo
- type SelfTestInfo
- type SmartStatus
- type SmartSupport
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 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:
- WithLibraryPath option
- 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.
- 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 ¶
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 ¶
GetDeviceInfo returns raw key/value device information for the given device.
func (*LibBackend) GetSMARTInfo ¶
GetSMARTInfo returns comprehensive SMART information for the given device.
func (*LibBackend) RunSelfTest ¶
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 ¶
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 ¶
WithSlogHandler sets a slog.Logger for the backend.
func WithTLogHandler ¶
WithTLogHandler sets a tlog.Logger for the 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.