exec

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package smartmontools provides Go bindings for interfacing with smartmontools to monitor and manage storage device health using S.M.A.R.T. data.

This file contains functions for parsing and managing the embedded drivedb.h database from smartmontools, which includes USB bridge device mappings.

Index

Constants

View Source
const (
	SmartAttrSSDLifeUsed       = smtypes.SmartAttrSSDLifeUsed
	SmartAttrWearLevelingCount = smtypes.SmartAttrWearLevelingCount
	SmartAttrSSDLifeLeft       = smtypes.SmartAttrSSDLifeLeft
	SmartAttrSandForceInternal = smtypes.SmartAttrSandForceInternal
	SmartAttrTotalLBAsWritten  = smtypes.SmartAttrTotalLBAsWritten
)

Shared SMART attribute constants used by exec backend helpers.

View Source
const DrivedbUpstreamCommit = "206c3572f51c43e7faf7f71be69b6eb263586e32"

DrivedbUpstreamCommit is the upstream smartmontools commit SHA from which the embedded drivedb.h was taken.

View Source
const DrivedbUpstreamDate = "2026-02-07T15:38:04Z"

DrivedbUpstreamDate is the commit date of DrivedbUpstreamCommit in RFC 3339 format.

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 exec backend.

type Backend

type Backend = smtypes.Backend

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

type Capabilities

type Capabilities = smtypes.Capabilities

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

type CapabilitiesOutput

type CapabilitiesOutput = smtypes.CapabilitiesOutput

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

type Cmd

type Cmd = smtypes.Cmd

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

type Commander

type Commander = smtypes.Commander

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

type Device

type Device = smtypes.Device

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

type DiscoveryBackend

type DiscoveryBackend = smtypes.DiscoveryBackend

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

type DiscoveryResult

type DiscoveryResult = smtypes.DiscoveryResult

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

type ExecBackend

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

ExecBackend is a Backend implementation that shells out to the smartctl binary.

func New

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

New creates a new exec-backed SMART backend.

func NewExecBackend

func NewExecBackend(opts ...Option) (*ExecBackend, error)

NewExecBackend preserves the legacy constructor name.

func (*ExecBackend) AbortSelfTest

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

AbortSelfTest aborts a running self-test on a device.

func (*ExecBackend) CheckHealth

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

CheckHealth checks if a device is healthy according to SMART.

func (*ExecBackend) Close

func (b *ExecBackend) Close() error

Close releases resources held by the backend.

func (*ExecBackend) DeviceTypeHint

func (b *ExecBackend) DeviceTypeHint(path string) (string, bool)

DeviceTypeHint returns a cached device type hint for the provided path.

func (*ExecBackend) DisableSMART

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

DisableSMART disables SMART monitoring on a device. Note: NVMe devices do not support disabling SMART, an error will be returned.

func (*ExecBackend) DiscoverDevices

func (b *ExecBackend) DiscoverDevices(ctx context.Context) ([]DiscoveryResult, error)

DiscoverDevices scans all available storage devices and probes each one to determine SMART readability and protocol compatibility.

func (*ExecBackend) EnableSMART

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

EnableSMART enables SMART monitoring on a device.

func (*ExecBackend) GetAvailableSelfTests

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

GetAvailableSelfTests returns the list of available self-test types and their durations for a device.

func (*ExecBackend) GetDeviceInfo

func (b *ExecBackend) GetDeviceInfo(ctx context.Context, devicePath string) (map[string]interface{}, error)

GetDeviceInfo retrieves basic device information.

func (*ExecBackend) GetSMARTInfo

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

GetSMARTInfo retrieves SMART information for a device.

func (*ExecBackend) Name

func (b *ExecBackend) Name() string

Name returns the backend identifier.

func (*ExecBackend) RunSelfTest

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

RunSelfTest initiates a SMART self-test.

func (*ExecBackend) ScanDevices

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

ScanDevices scans for available storage devices. It first attempts --scan-open (which performs an open on each drive to verify accessibility) and falls back to --scan on failure. --scan-open may fail in container sandboxes, on older kernels, or when the caller lacks the required permissions; --scan still returns the device list without the open step.

func (*ExecBackend) SetDeviceTypeHint

func (b *ExecBackend) SetDeviceTypeHint(path, deviceType string)

SetDeviceTypeHint stores a device type hint in the backend cache.

func (*ExecBackend) SmartctlPath

func (b *ExecBackend) SmartctlPath() string

SmartctlPath returns the resolved path to the smartctl binary.

type ExitCodeInfo

type ExitCodeInfo = smtypes.ExitCodeInfo

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

type Flags

type Flags = smtypes.Flags

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

type LogAdapter

type LogAdapter = smtypes.LogAdapter

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

type Message

type Message = smtypes.Message

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

type NvmeControllerCapabilities

type NvmeControllerCapabilities = smtypes.NvmeControllerCapabilities

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

type NvmeOptionalAdminCommands

type NvmeOptionalAdminCommands = smtypes.NvmeOptionalAdminCommands

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

type NvmeSmartHealth

type NvmeSmartHealth = smtypes.NvmeSmartHealth

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

type NvmeSmartTestLog

type NvmeSmartTestLog = smtypes.NvmeSmartTestLog

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

type OfflineDataCollection

type OfflineDataCollection = smtypes.OfflineDataCollection

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

type Option

type Option func(*ExecBackend)

Option configures an ExecBackend.

func WithCommander

func WithCommander(commander Commander) Option

WithCommander sets a custom commander, typically for testing.

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 custom slog.Logger for the backend.

func WithSmartctlPath

func WithSmartctlPath(path string) Option

WithSmartctlPath sets a custom path to the smartctl binary.

func WithTLogHandler

func WithTLogHandler(logger *tlog.Logger) Option

WithTLogHandler sets a custom tlog.Logger for the backend.

type PollingMinutes

type PollingMinutes = smtypes.PollingMinutes

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

type PowerOnTime

type PowerOnTime = smtypes.PowerOnTime

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

type ProgressCallback

type ProgressCallback = smtypes.ProgressCallback

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

type Raw

type Raw = smtypes.Raw

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

type SMARTInfo

type SMARTInfo = smtypes.SMARTInfo

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

type SelfTest

type SelfTest = smtypes.SelfTest

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

type SelfTestInfo

type SelfTestInfo = smtypes.SelfTestInfo

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

type SmartAttribute

type SmartAttribute = smtypes.SmartAttribute

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

type SmartStatus

type SmartStatus = smtypes.SmartStatus

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

type SmartSupport

type SmartSupport = smtypes.SmartSupport

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

type SmartctlInfo

type SmartctlInfo = smtypes.SmartctlInfo

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

type StatusField

type StatusField = smtypes.StatusField

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

type Temperature

type Temperature = smtypes.Temperature

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

type UserCapacity

type UserCapacity = smtypes.UserCapacity

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

Jump to

Keyboard shortcuts

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