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
- type AtaSmartData
- type Backend
- type Capabilities
- type CapabilitiesOutput
- type Cmd
- type Commander
- type Device
- type DiscoveryBackend
- type DiscoveryResult
- type ExecBackend
- func (b *ExecBackend) AbortSelfTest(ctx context.Context, devicePath string) error
- func (b *ExecBackend) CheckHealth(ctx context.Context, devicePath string) (bool, error)
- func (b *ExecBackend) Close() error
- func (b *ExecBackend) DeviceTypeHint(path string) (string, bool)
- func (b *ExecBackend) DisableSMART(ctx context.Context, devicePath string) error
- func (b *ExecBackend) DiscoverDevices(ctx context.Context) ([]DiscoveryResult, error)
- func (b *ExecBackend) EnableSMART(ctx context.Context, devicePath string) error
- func (b *ExecBackend) GetAvailableSelfTests(ctx context.Context, devicePath string) (*SelfTestInfo, error)
- func (b *ExecBackend) GetDeviceInfo(ctx context.Context, devicePath string) (map[string]interface{}, error)
- func (b *ExecBackend) GetSMARTInfo(ctx context.Context, devicePath string) (*SMARTInfo, error)
- func (b *ExecBackend) Name() string
- func (b *ExecBackend) RunSelfTest(ctx context.Context, devicePath string, testType string) error
- func (b *ExecBackend) ScanDevices(ctx context.Context) ([]Device, error)
- func (b *ExecBackend) SetDeviceTypeHint(path, deviceType string)
- func (b *ExecBackend) SmartctlPath() string
- type ExitCodeInfo
- type Flags
- type LogAdapter
- type Message
- type NvmeControllerCapabilities
- type NvmeOptionalAdminCommands
- type NvmeSmartHealth
- type NvmeSmartTestLog
- type OfflineDataCollection
- type Option
- type PollingMinutes
- type PowerOnTime
- type ProgressCallback
- type Raw
- type SMARTInfo
- type SelfTest
- type SelfTestInfo
- type SmartAttribute
- type SmartStatus
- type SmartSupport
- type SmartctlInfo
- type StatusField
- type Temperature
- type UserCapacity
Constants ¶
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.
const DrivedbUpstreamCommit = "206c3572f51c43e7faf7f71be69b6eb263586e32"
DrivedbUpstreamCommit is the upstream smartmontools commit SHA from which the embedded drivedb.h was taken.
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 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 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 ¶
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 ¶
GetSMARTInfo retrieves SMART information for a device.
func (*ExecBackend) RunSelfTest ¶
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 LogAdapter ¶
type LogAdapter = smtypes.LogAdapter
Shared interface aliases keep the exec backend decoupled from the root package.
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 ¶
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 ¶
WithSlogHandler sets a custom slog.Logger for the backend.
func WithSmartctlPath ¶
WithSmartctlPath sets a custom path to the smartctl binary.
func WithTLogHandler ¶
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 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.