smartmontools  SVN Rev 4325
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 () throw ()
 
virtual std::string get_os_version_str ()
 Return info string about build host and/or OS version. More...
 
virtual std::string get_valid_dev_types_str ()
 Return valid args for device type option/directive. More...
 
virtual std::string get_app_examples (const char *appname)
 Return example string for program 'appname'. More...
 
virtual int64_t get_timer_usec ()
 Get microseconds since some unspecified starting point. More...
 
virtual bool disable_system_auto_standby (bool disable)
 Disable/Enable system auto standby/sleep mode. More...
 
const smart_device::error_infoget_err () const
 Get last error info struct. More...
 
int get_errno () const
 Get last error number. More...
 
const char * get_errmsg () const
 Get last error message. More...
 
bool set_err (int no, const char *msg,...) __attribute_format_printf(3
 Set last error number and message. More...
 
bool bool set_err (const smart_device::error_info &err)
 Set last error info struct. More...
 
void clear_err ()
 Clear last error info. More...
 
bool set_err (int no)
 Set last error number and default message. More...
 
bool set_err_var (smart_device::error_info *err, int no)
 Set last error number and default message to any error_info. More...
 
virtual const char * get_msg_for_errno (int no)
 Convert error number into message, used by set_err(no). More...
 
virtual smart_deviceget_smart_device (const char *name, const char *type)
 Return device object for device 'name' with some 'type'. More...
 
virtual bool scan_smart_devices (smart_device_list &devlist, const char *type, const char *pattern=0)=0
 Fill 'devlist' with devices of some 'type' with device names specified by some optional 'pattern'. More...
 
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'. More...
 
virtual ata_deviceautodetect_sat_device (scsi_device *scsidev, const unsigned char *inqdata, unsigned inqsize)
 Try to detect a SAT device behind a SCSI interface. More...
 
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. More...
 

Static Public Member Functions

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

Protected Member Functions

virtual ata_deviceget_ata_device (const char *name, const char *type)=0
 Return standard ATA device. More...
 
virtual scsi_deviceget_scsi_device (const char *name, const char *type)=0
 Return standard SCSI device. More...
 
virtual nvme_deviceget_nvme_device (const char *name, const char *type, unsigned nsid)
 Return standard NVMe device. More...
 
virtual smart_deviceautodetect_smart_device (const char *name)=0
 Autodetect device if no device type specified. More...
 
virtual smart_deviceget_custom_smart_device (const char *name, const char *type)
 Return device for platform specific 'type'. More...
 
virtual std::string get_valid_custom_dev_types_str ()
 Return valid 'type' args accepted by above. More...
 
virtual ata_deviceget_sat_device (const char *type, scsi_device *scsidev)
 Return ATA->SCSI filter for a SAT or USB 'type'. More...
 

Static Protected Member Functions

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

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. More...
 

Friends

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

Detailed Description

The platform interface abstraction.

Definition at line 865 of file dev_interface.h.

Constructor & Destructor Documentation

smart_interface::smart_interface ( )
inline

Definition at line 872 of file dev_interface.h.

virtual smart_interface::~smart_interface ( )
throw (
)
inlinevirtual

Definition at line 875 of file dev_interface.h.

smart_interface::smart_interface ( const smart_interface )
private

Member Function Documentation

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 1564 of file scsiata.cpp.

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

Clear last error info.

Definition at line 931 of file dev_interface.h.

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 329 of file dev_interface.cpp.

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 os_win32::win_smart_interface, os_linux::linux_smart_interface, os_freebsd::freebsd_smart_interface, os::darwin_smart_interface, os::legacy_smart_interface, and generic::generic_smart_interface.

Definition at line 294 of file dev_interface.cpp.

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

Return device for platform specific 'type'.

Default implementation returns 0.

Reimplemented in os_win32::win_smart_interface, os_linux::linux_smart_interface, os_freebsd::freebsd_smart_interface, and generic::generic_smart_interface.

Definition at line 459 of file dev_interface.cpp.

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

Get last error info struct.

Definition at line 911 of file dev_interface.h.

const char* smart_interface::get_errmsg ( ) const
inline

Get last error message.

Definition at line 917 of file dev_interface.h.

int smart_interface::get_errno ( ) const
inline

Get last error number.

Definition at line 914 of file dev_interface.h.

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 359 of file dev_interface.cpp.

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_win32::win_smart_interface, os_linux::linux_smart_interface, and os_freebsd::freebsd_smart_interface.

Definition at line 453 of file dev_interface.cpp.

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_win32::win_smart_interface, os_linux::linux_smart_interface, os_freebsd::freebsd_smart_interface, and os::darwin_smart_interface.

Definition at line 275 of file dev_interface.cpp.

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 1487 of file scsiata.cpp.

virtual scsi_device* smart_interface::get_scsi_device ( const char *  name,
const char *  type 
)
protectedpure virtual
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 368 of file dev_interface.cpp.

int64_t smart_interface::get_timer_usec ( )
virtual

Get microseconds since some unspecified starting point.

Used only for command duration measurements in debug outputs. Returns -1 if unsupported. Default implementation uses clock_gettime(), gettimeofday() or ftime().

Reimplemented in os_win32::win_smart_interface.

Definition at line 299 of file dev_interface.cpp.

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 1594 of file scsiata.cpp.

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 os_win32::win_smart_interface, os_linux::linux_smart_interface, os_freebsd::freebsd_smart_interface, and generic::generic_smart_interface.

Definition at line 464 of file dev_interface.cpp.

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 280 of file dev_interface.cpp.

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 341 of file dev_legacy.cpp.

void smart_interface::operator= ( const smart_interface )
private
virtual bool smart_interface::scan_smart_devices ( smart_device_list devlist,
const char *  type,
const char *  pattern = 0 
)
pure 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.

Implemented in os_win32::win_smart_interface, os_linux::linux_smart_interface, os_freebsd::freebsd_smart_interface, os::darwin_smart_interface, os::legacy_smart_interface, and generic::generic_smart_interface.

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.

Definition at line 434 of file dev_interface.cpp.

static void smart_interface::set ( smart_interface intf)
inlinestaticprotected

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

Definition at line 1019 of file dev_interface.h.

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 334 of file dev_interface.cpp.

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

Set last error info struct.

Definition at line 927 of file dev_interface.h.

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 345 of file dev_interface.cpp.

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 350 of file dev_interface.cpp.

Friends And Related Function Documentation

smart_interface* smi ( )
friend

Global access to the (usually singleton) smart_interface.

Definition at line 1039 of file dev_interface.h.

Member Data Documentation

smart_device::error_info smart_interface::m_err
private

Definition at line 1024 of file dev_interface.h.

smart_interface * smart_interface::s_instance
staticprivate

Pointer to the interface object.

Definition at line 1027 of file dev_interface.h.


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