smartmontools SVN Rev 5597
Utility to control and monitor storage systems with "S.M.A.R.T."
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
smart_interface Class Referenceabstract

The platform interface abstraction. More...

#include <dev_interface.h>

Collaboration diagram for smart_interface:
Collaboration graph
[legend]

Public Member Functions

 smart_interface ()
 
virtual ~smart_interface ()
 
virtual std::string get_os_version_str ()
 Return info string about build host and/or OS version.
 
virtual std::string get_valid_dev_types_str ()
 Return valid args for device type option/directive.
 
virtual std::string get_app_examples (const char *appname)
 Return example string for program 'appname'.
 
virtual bool disable_system_auto_standby (bool disable)
 Disable/Enable system auto standby/sleep mode.
 
const smart_device::error_infoget_err () const
 Get last error info struct.
 
int get_errno () const
 Get last error number.
 
const char * get_errmsg () const
 Get last error message.
 
bool set_err (int no, const char *msg,...) __attribute_format_printf(3
 Set last error number and message.
 
bool decltype(nullptr) set_err_np (int no, const char *msg,...) __attribute_format_printf(3
 Set last error number and message.
 
bool decltype(nullptr) bool set_err (const smart_device::error_info &err)
 Set last error info struct.
 
void clear_err ()
 Clear last error info.
 
bool set_err (int no)
 Set last error number and default message.
 
bool set_err_var (smart_device::error_info *err, int no)
 Set last error number and default message to any error_info.
 
virtual const char * get_msg_for_errno (int no)
 Convert error number into message, used by set_err(no).
 
virtual smart_deviceget_smart_device (const char *name, const char *type)
 Return device object for device 'name' with some 'type'.
 
virtual bool scan_smart_devices (smart_device_list &devlist, const char *type, const char *pattern=0)
 Fill 'devlist' with devices of some 'type' with device names specified by some optional 'pattern'.
 
virtual bool scan_smart_devices (smart_device_list &devlist, const smart_devtype_list &types, const char *pattern=0)
 Fill 'devlist' with devices of all 'types' with device names specified by some optional 'pattern'.
 
virtual std::string get_unique_dev_name (const char *name, const char *type) const
 Return unique device name which is (only) suitable for duplicate detection.
 
virtual bool is_raid_dev_type (const char *type) const
 Return true if the 'type' string contains a RAID drive number.
 
virtual ata_deviceautodetect_sat_device (scsi_device *scsidev, const unsigned char *inqdata, unsigned inqsize)
 Try to detect a SAT device behind a SCSI interface.
 
virtual const char * get_usb_dev_type_by_id (int vendor_id, int product_id, int version=-1)
 Get type name for USB device with known VENDOR:PRODUCT ID.
 

Static Public Member Functions

static void init ()
 Initialize platform interface and register with smi().
 

Protected Member Functions

virtual ata_deviceget_ata_device (const char *name, const char *type)=0
 Return standard ATA device.
 
virtual scsi_deviceget_scsi_device (const char *name, const char *type)=0
 Return standard SCSI device.
 
virtual nvme_deviceget_nvme_device (const char *name, const char *type, unsigned nsid)
 Return standard NVMe device.
 
virtual smart_deviceautodetect_smart_device (const char *name)=0
 Autodetect device if no device type specified.
 
virtual smart_deviceget_custom_smart_device (const char *name, const char *type)
 Return device for platform specific 'type'.
 
virtual std::string get_valid_custom_dev_types_str ()
 Return valid 'type' args accepted by above.
 
virtual smart_deviceget_scsi_passthrough_device (const char *type, scsi_device *scsidev)
 Return ATA->SCSI of NVMe->SCSI filter for a SAT, SNT or USB 'type'.
 
virtual ata_deviceget_sat_device (const char *type, scsi_device *scsidev)
 Return ATA->SCSI filter for a SAT or USB 'type'.
 
virtual nvme_deviceget_snt_device (const char *type, scsi_device *scsidev)
 Return NVMe->SCSI filter for a SNT or USB 'type'.
 
virtual ata_deviceget_intelliprop_device (const char *type, ata_device *atadev)
 Return filter for Intelliprop controllers.
 
virtual ata_deviceget_jmb39x_device (const char *type, smart_device *smartdev)
 Return JMB93x->ATA filter.
 

Static Protected Member Functions

static void set (smart_interface *intf)
 Set interface to use, must be called from init().
 

Private Member Functions

 smart_interface (const smart_interface &)
 
void operator= (const smart_interface &)
 

Private Attributes

smart_device::error_info m_err
 

Static Private Attributes

static smart_interfaces_instance
 Pointer to the interface object.
 

Friends

smart_interfacesmi ()
 Global access to the (usually singleton) smart_interface.
 

Detailed Description

The platform interface abstraction.

Definition at line 910 of file dev_interface.h.

Constructor & Destructor Documentation

◆ smart_interface() [1/2]

smart_interface::smart_interface ( )
inline

Definition at line 917 of file dev_interface.h.

◆ ~smart_interface()

virtual smart_interface::~smart_interface ( )
inlinevirtual

Definition at line 920 of file dev_interface.h.

◆ smart_interface() [2/2]

smart_interface::smart_interface ( const smart_interface )
private

Member Function Documentation

◆ autodetect_sat_device()

ata_device * smart_interface::autodetect_sat_device ( scsi_device scsidev,
const unsigned char *  inqdata,
unsigned  inqsize 
)
virtual

Try to detect a SAT device behind a SCSI interface.

Inquiry data can be passed if available. Return appropriate device if yes, otherwise 0. Override only if platform needs special handling.

Definition at line 1486 of file scsiata.cpp.

◆ autodetect_smart_device()

virtual smart_device * smart_interface::autodetect_smart_device ( const char *  name)
protectedpure virtual

◆ clear_err()

void smart_interface::clear_err ( )
inline

Clear last error info.

Definition at line 978 of file dev_interface.h.

◆ disable_system_auto_standby()

bool smart_interface::disable_system_auto_standby ( bool  disable)
virtual

Disable/Enable system auto standby/sleep mode.

Return false if unsupported or if system is running on battery. Default implementation returns false.

Reimplemented in os_win32::win_smart_interface.

Definition at line 324 of file dev_interface.cpp.

◆ get_app_examples()

std::string smart_interface::get_app_examples ( const char *  appname)
virtual

Return example string for program 'appname'.

Default implementation returns empty string. For the migration of print_smartctl_examples(), function is allowed to print examples to stdout. TODO: Remove this hack.

Reimplemented in generic::generic_smart_interface, os::legacy_smart_interface, os::darwin_smart_interface, os_freebsd::freebsd_smart_interface, os_linux::linux_smart_interface, os_netbsd::netbsd_smart_interface, os_openbsd::openbsd_smart_interface, and os_win32::win_smart_interface.

Definition at line 319 of file dev_interface.cpp.

◆ get_ata_device()

virtual ata_device * smart_interface::get_ata_device ( const char *  name,
const char *  type 
)
protectedpure virtual

◆ get_custom_smart_device()

smart_device * smart_interface::get_custom_smart_device ( const char *  name,
const char *  type 
)
protectedvirtual

◆ get_err()

const smart_device::error_info & smart_interface::get_err ( ) const
inline

Get last error info struct.

Definition at line 950 of file dev_interface.h.

◆ get_errmsg()

const char * smart_interface::get_errmsg ( ) const
inline

Get last error message.

Definition at line 956 of file dev_interface.h.

◆ get_errno()

int smart_interface::get_errno ( ) const
inline

Get last error number.

Definition at line 953 of file dev_interface.h.

◆ get_intelliprop_device()

ata_device * smart_interface::get_intelliprop_device ( const char *  type,
ata_device atadev 
)
protectedvirtual

Return filter for Intelliprop controllers.

Definition at line 292 of file dev_intelliprop.cpp.

◆ get_jmb39x_device()

ata_device * smart_interface::get_jmb39x_device ( const char *  type,
smart_device smartdev 
)
protectedvirtual

Return JMB93x->ATA filter.

Device 'smartdev' is used for ATA or SCSI R/W access. Return 0 and delete 'scsidev' on error. Override only if platform needs special handling.

Definition at line 684 of file dev_jmb39x_raid.cpp.

◆ get_msg_for_errno()

const char * smart_interface::get_msg_for_errno ( int  no)
virtual

Convert error number into message, used by set_err(no).

Default implementation returns strerror(no).

Definition at line 367 of file dev_interface.cpp.

◆ get_nvme_device()

nvme_device * smart_interface::get_nvme_device ( const char *  name,
const char *  type,
unsigned  nsid 
)
protectedvirtual

Return standard NVMe device.

Default implementation returns 0.

Reimplemented in os::darwin_smart_interface, os_freebsd::freebsd_smart_interface, os_linux::linux_smart_interface, os_netbsd::netbsd_smart_interface, and os_win32::win_smart_interface.

Definition at line 533 of file dev_interface.cpp.

◆ get_os_version_str()

std::string smart_interface::get_os_version_str ( )
virtual

Return info string about build host and/or OS version.

Default implementation returns SMARTMONTOOLS_BUILD_HOST.

Reimplemented in os::darwin_smart_interface, os_freebsd::freebsd_smart_interface, os_linux::linux_smart_interface, os_netbsd::netbsd_smart_interface, os_openbsd::openbsd_smart_interface, and os_win32::win_smart_interface.

Definition at line 298 of file dev_interface.cpp.

◆ get_sat_device()

ata_device * smart_interface::get_sat_device ( const char *  type,
scsi_device scsidev 
)
protectedvirtual

Return ATA->SCSI filter for a SAT or USB 'type'.

Device 'scsidev' is used for SCSI access. Return 0 and delete 'scsidev' on error. Override only if platform needs special handling.

Definition at line 1405 of file scsiata.cpp.

◆ get_scsi_device()

virtual scsi_device * smart_interface::get_scsi_device ( const char *  name,
const char *  type 
)
protectedpure virtual

◆ get_scsi_passthrough_device()

smart_device * smart_interface::get_scsi_passthrough_device ( const char *  type,
scsi_device scsidev 
)
protectedvirtual

Return ATA->SCSI of NVMe->SCSI filter for a SAT, SNT or USB 'type'.

Uses get_sat_device and get_snt_device. Return 0 and delete 'scsidev' on error.

Definition at line 548 of file dev_interface.cpp.

◆ get_smart_device()

smart_device * smart_interface::get_smart_device ( const char *  name,
const char *  type 
)
virtual

Return device object for device 'name' with some 'type'.

'type' is 0 if not specified by user. Return 0 on error. Default implementation selects between ata, scsi and custom device.

Definition at line 408 of file dev_interface.cpp.

◆ get_snt_device()

nvme_device * smart_interface::get_snt_device ( const char *  type,
scsi_device scsidev 
)
protectedvirtual

Return NVMe->SCSI filter for a SNT or USB 'type'.

Device 'scsidev' is used for SCSI access. Return 0 and delete 'scsidev' on error. Override only if platform needs special handling.

Definition at line 398 of file scsinvme.cpp.

◆ get_unique_dev_name()

std::string smart_interface::get_unique_dev_name ( const char *  name,
const char *  type 
) const
virtual

Return unique device name which is (only) suitable for duplicate detection.

Default implementation resolves symlinks on POSIX systems and appends " [type]" if is_raid_dev_type(type)' returns true.

Definition at line 372 of file dev_interface.cpp.

◆ get_usb_dev_type_by_id()

const char * smart_interface::get_usb_dev_type_by_id ( int  vendor_id,
int  product_id,
int  version = -1 
)
virtual

Get type name for USB device with known VENDOR:PRODUCT ID.

Return name if device known and supported, otherwise 0.

Definition at line 1518 of file scsiata.cpp.

◆ get_valid_custom_dev_types_str()

std::string smart_interface::get_valid_custom_dev_types_str ( )
protectedvirtual

Return valid 'type' args accepted by above.

This is called in get_valid_dev_types_str(). Default implementation returns empty string.

Reimplemented in generic::generic_smart_interface, os_freebsd::freebsd_smart_interface, os_linux::linux_smart_interface, os_netbsd::netbsd_smart_interface, os_openbsd::openbsd_smart_interface, and os_win32::win_smart_interface.

Definition at line 543 of file dev_interface.cpp.

◆ get_valid_dev_types_str()

std::string smart_interface::get_valid_dev_types_str ( )
virtual

Return valid args for device type option/directive.

Default implementation returns "ata, scsi, sat, usb*..." concatenated with result from get_valid_custom_dev_types_str().

Definition at line 303 of file dev_interface.cpp.

◆ init()

void smart_interface::init ( )
static

Initialize platform interface and register with smi().

Initialize platform interface and register with smi()

Must be implemented by platform module and register interface with set()

Definition at line 334 of file dev_legacy.cpp.

◆ is_raid_dev_type()

bool smart_interface::is_raid_dev_type ( const char *  type) const
virtual

Return true if the 'type' string contains a RAID drive number.

Default implementation returns true if 'type' starts with '[^,]+,[0-9]' but not with 'sat,'.

Definition at line 392 of file dev_interface.cpp.

◆ operator=()

void smart_interface::operator= ( const smart_interface )
private

◆ scan_smart_devices() [1/2]

bool smart_interface::scan_smart_devices ( smart_device_list devlist,
const char *  type,
const char *  pattern = 0 
)
virtual

Fill 'devlist' with devices of some 'type' with device names specified by some optional 'pattern'.

Use platform specific default if 'type' is empty or 0. Return false on error. Default implementation returns false;

Reimplemented in generic::generic_smart_interface, os::legacy_smart_interface, os::darwin_smart_interface, os_freebsd::freebsd_smart_interface, os_netbsd::netbsd_smart_interface, os_openbsd::openbsd_smart_interface, and os_win32::win_smart_interface.

Definition at line 508 of file dev_interface.cpp.

◆ scan_smart_devices() [2/2]

bool smart_interface::scan_smart_devices ( smart_device_list devlist,
const smart_devtype_list types,
const char *  pattern = 0 
)
virtual

Fill 'devlist' with devices of all 'types' with device names specified by some optional 'pattern'.

Use platform specific default if 'types' is empty. Return false on error. Default implementation calls above function for all types and concatenates the results.

Reimplemented in os_linux::linux_smart_interface.

Definition at line 514 of file dev_interface.cpp.

◆ set()

static void smart_interface::set ( smart_interface intf)
inlinestaticprotected

Set interface to use, must be called from init().

Definition at line 1100 of file dev_interface.h.

◆ set_err() [1/3]

bool decltype(nullptr) bool smart_interface::set_err ( const smart_device::error_info err)
inline

Set last error info struct.

Definition at line 974 of file dev_interface.h.

◆ set_err() [2/3]

bool smart_interface::set_err ( int  no)

Set last error number and default message.

Message is retrieved from get_msg_for_errno(no).

Definition at line 353 of file dev_interface.cpp.

◆ set_err() [3/3]

bool smart_interface::set_err ( int  no,
const char *  msg,
  ... 
)

Set last error number and message.

Printf()-like formatting is supported. Returns false always to allow use as a return expression.

Definition at line 329 of file dev_interface.cpp.

◆ set_err_np()

decltype(nullptr) smart_interface::set_err_np ( int  no,
const char *  msg,
  ... 
)

Set last error number and message.

Printf()-like formatting is supported. Returns nullptr always to allow use as a return expression of any pointer type.

Definition at line 340 of file dev_interface.cpp.

◆ set_err_var()

bool smart_interface::set_err_var ( smart_device::error_info err,
int  no 
)

Set last error number and default message to any error_info.

Used by set_err(no).

Definition at line 358 of file dev_interface.cpp.

Friends And Related Function Documentation

◆ smi

smart_interface * smi ( )
friend

Global access to the (usually singleton) smart_interface.

Definition at line 1120 of file dev_interface.h.

Member Data Documentation

◆ m_err

smart_device::error_info smart_interface::m_err
private

Definition at line 1105 of file dev_interface.h.

◆ s_instance

smart_interface * smart_interface::s_instance
staticprivate

Pointer to the interface object.

Definition at line 1108 of file dev_interface.h.


The documentation for this class was generated from the following files: