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

Base class for all devices. More...

#include <dev_interface.h>

Collaboration diagram for smart_device:
Collaboration graph
[legend]

Classes

struct  device_info
 Device info strings. More...
 
struct  error_info
 Error (number,message) pair. More...
 

Public Member Functions

virtual ~smart_device ()
 
bool is_ata () const
 Return true if ATA device.
 
bool is_scsi () const
 Return true if SCSI device.
 
bool is_nvme () const
 Return true if NVMe device.
 
ata_deviceto_ata ()
 Downcast to ATA device.
 
const ata_deviceto_ata () const
 Downcast to ATA device (const).
 
scsi_deviceto_scsi ()
 Downcast to SCSI device.
 
const scsi_deviceto_scsi () const
 Downcast to SCSI device (const).
 
nvme_deviceto_nvme ()
 Downcast to NVMe device.
 
const nvme_deviceto_nvme () const
 Downcast to NVMe device (const).
 
const device_infoget_info () const
 Get device info struct.
 
const char * get_dev_name () const
 Get device (path)name.
 
const char * get_info_name () const
 Get informal name.
 
const char * get_dev_type () const
 Get device type.
 
const char * get_req_type () const
 Get type requested by user, empty if none.
 
const 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.
 
virtual bool is_syscall_unsup () const
 Return true if last error indicates an unsupported system call.
 
bool set_err (int no, const char *msg,...) __attribute_format_printf(3
 Set last error number and message.
 
bool bool set_err (const 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.
 
virtual bool is_open () const =0
 Return true if device is open.
 
virtual bool open ()=0
 Open device, return false on error.
 
virtual bool close ()=0
 Close device, return false on error.
 
virtual smart_deviceautodetect_open ()
 Open device with autodetection support.
 
virtual bool is_powered_down ()
 Early test if device is powered up or down.
 
virtual bool owns (const smart_device *dev) const
 Return true if other device is owned by this device.
 
virtual void release (const smart_device *dev)
 Release ownership of other device.
 

Static Public Member Functions

static int get_num_objects ()
 Get current number of allocated 'smart_device' objects.
 

Protected Types

enum  do_not_use_in_implementation_classes { never_called }
 Dummy enum for dummy constructor. More...
 

Protected Member Functions

 smart_device (smart_interface *intf, const char *dev_name, const char *dev_type, const char *req_type)
 Constructor to init interface and device info.
 
 smart_device (do_not_use_in_implementation_classes)
 Dummy constructor for abstract classes.
 
device_infoset_info ()
 R/W access to device info struct.
 
smart_interfacesmi ()
 Get interface which produced this object.
 
const smart_interfacesmi () const
 Get interface which produced this object (const).
 

Private Member Functions

 smart_device (const smart_device &)
 
void operator= (const smart_device &)
 

Private Attributes

smart_interfacem_intf
 
device_info m_info
 
error_info m_err
 
ata_devicem_ata_ptr
 
scsi_devicem_scsi_ptr
 
nvme_devicem_nvme_ptr
 

Static Private Attributes

static int s_num_objects = 0
 

Friends

class ata_device
 
class scsi_device
 
class nvme_device
 

Detailed Description

Base class for all devices.

Definition at line 32 of file dev_interface.h.

Member Enumeration Documentation

◆ do_not_use_in_implementation_classes

Dummy enum for dummy constructor.

Enumerator
never_called 

Definition at line 72 of file dev_interface.h.

Constructor & Destructor Documentation

◆ smart_device() [1/3]

smart_device::smart_device ( smart_interface intf,
const char *  dev_name,
const char *  dev_type,
const char *  req_type 
)
protected

Constructor to init interface and device info.

Must be called in implementation classes.

Definition at line 33 of file dev_interface.cpp.

◆ smart_device() [2/3]

smart_device::smart_device ( do_not_use_in_implementation_classes  )
explicitprotected

Dummy constructor for abstract classes.

Must never be called in implementation classes.

Definition at line 41 of file dev_interface.cpp.

◆ ~smart_device()

smart_device::~smart_device ( )
virtual

Definition at line 47 of file dev_interface.cpp.

◆ smart_device() [3/3]

smart_device::smart_device ( const smart_device )
private

Member Function Documentation

◆ autodetect_open()

smart_device * smart_device::autodetect_open ( )
virtual

◆ clear_err()

void smart_device::clear_err ( )
inline

Clear last error info.

Definition at line 168 of file dev_interface.h.

◆ close()

virtual bool smart_device::close ( )
pure virtual

◆ get_dev_name()

const char * smart_device::get_dev_name ( ) const
inline

Get device (path)name.

Definition at line 122 of file dev_interface.h.

◆ get_dev_type()

const char * smart_device::get_dev_type ( ) const
inline

Get device type.

Definition at line 128 of file dev_interface.h.

◆ get_err()

const error_info & smart_device::get_err ( ) const
inline

Get last error info struct.

Definition at line 144 of file dev_interface.h.

◆ get_errmsg()

const char * smart_device::get_errmsg ( ) const
inline

Get last error message.

Definition at line 150 of file dev_interface.h.

◆ get_errno()

int smart_device::get_errno ( ) const
inline

Get last error number.

Definition at line 147 of file dev_interface.h.

◆ get_info()

const device_info & smart_device::get_info ( ) const
inline

Get device info struct.

Definition at line 118 of file dev_interface.h.

◆ get_info_name()

const char * smart_device::get_info_name ( ) const
inline

Get informal name.

Definition at line 125 of file dev_interface.h.

◆ get_num_objects()

static int smart_device::get_num_objects ( )
inlinestatic

Get current number of allocated 'smart_device' objects.

Definition at line 176 of file dev_interface.h.

◆ get_req_type()

const char * smart_device::get_req_type ( ) const
inline

Get type requested by user, empty if none.

Definition at line 131 of file dev_interface.h.

◆ is_ata()

bool smart_device::is_ata ( ) const
inline

Return true if ATA device.

Definition at line 86 of file dev_interface.h.

◆ is_nvme()

bool smart_device::is_nvme ( ) const
inline

Return true if NVMe device.

Definition at line 92 of file dev_interface.h.

◆ is_open()

virtual bool smart_device::is_open ( ) const
pure virtual

◆ is_powered_down()

bool smart_device::is_powered_down ( )
virtual

Early test if device is powered up or down.

Can be used without calling 'open()' first! Return true when device is powered down, false when powered up. If this function is not implemented or the mode cannot be determined, return false. Default implementation returns false.

Reimplemented in os_win32::win_ata_device.

Definition at line 85 of file dev_interface.cpp.

◆ is_scsi()

bool smart_device::is_scsi ( ) const
inline

Return true if SCSI device.

Definition at line 89 of file dev_interface.h.

◆ is_syscall_unsup()

bool smart_device::is_syscall_unsup ( ) const
virtual

Return true if last error indicates an unsupported system call.

Default implementation returns true on ENOSYS and ENOTSUP.

Definition at line 52 of file dev_interface.cpp.

◆ open()

virtual bool smart_device::open ( )
pure virtual

◆ operator=()

void smart_device::operator= ( const smart_device )
private

◆ owns()

bool smart_device::owns ( const smart_device dev) const
virtual

Return true if other device is owned by this device.

Default implementation returns false.

Reimplemented in tunnelled_device_base.

Definition at line 90 of file dev_interface.cpp.

◆ release()

void smart_device::release ( const smart_device dev)
virtual

◆ set_err() [1/3]

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

Set last error info struct.

Definition at line 164 of file dev_interface.h.

◆ set_err() [2/3]

bool smart_device::set_err ( int  no)

Set last error number and default message.

Message is retrieved from interface's get_msg_for_errno(no).

Definition at line 74 of file dev_interface.cpp.

◆ set_err() [3/3]

bool smart_device::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 63 of file dev_interface.cpp.

◆ set_info()

device_info & smart_device::set_info ( )
inlineprotected

R/W access to device info struct.

Definition at line 136 of file dev_interface.h.

◆ smi() [1/2]

smart_interface * smart_device::smi ( )
inlineprotected

Get interface which produced this object.

Definition at line 224 of file dev_interface.h.

◆ smi() [2/2]

const smart_interface * smart_device::smi ( ) const
inlineprotected

Get interface which produced this object (const).

Definition at line 227 of file dev_interface.h.

◆ to_ata() [1/2]

ata_device * smart_device::to_ata ( )
inline

Downcast to ATA device.

Definition at line 96 of file dev_interface.h.

◆ to_ata() [2/2]

const ata_device * smart_device::to_ata ( ) const
inline

Downcast to ATA device (const).

Definition at line 99 of file dev_interface.h.

◆ to_nvme() [1/2]

nvme_device * smart_device::to_nvme ( )
inline

Downcast to NVMe device.

Definition at line 108 of file dev_interface.h.

◆ to_nvme() [2/2]

const nvme_device * smart_device::to_nvme ( ) const
inline

Downcast to NVMe device (const).

Definition at line 111 of file dev_interface.h.

◆ to_scsi() [1/2]

scsi_device * smart_device::to_scsi ( )
inline

Downcast to SCSI device.

Definition at line 102 of file dev_interface.h.

◆ to_scsi() [2/2]

const scsi_device * smart_device::to_scsi ( ) const
inline

Downcast to SCSI device (const).

Definition at line 105 of file dev_interface.h.

Friends And Related Function Documentation

◆ ata_device

friend class ata_device
friend

Definition at line 238 of file dev_interface.h.

◆ nvme_device

friend class nvme_device
friend

Definition at line 242 of file dev_interface.h.

◆ scsi_device

friend class scsi_device
friend

Definition at line 240 of file dev_interface.h.

Member Data Documentation

◆ m_ata_ptr

ata_device* smart_device::m_ata_ptr
private

Definition at line 239 of file dev_interface.h.

◆ m_err

error_info smart_device::m_err
private

Definition at line 234 of file dev_interface.h.

◆ m_info

device_info smart_device::m_info
private

Definition at line 233 of file dev_interface.h.

◆ m_intf

smart_interface* smart_device::m_intf
private

Definition at line 232 of file dev_interface.h.

◆ m_nvme_ptr

nvme_device* smart_device::m_nvme_ptr
private

Definition at line 243 of file dev_interface.h.

◆ m_scsi_ptr

scsi_device* smart_device::m_scsi_ptr
private

Definition at line 241 of file dev_interface.h.

◆ s_num_objects

int smart_device::s_num_objects = 0
staticprivate

Definition at line 246 of file dev_interface.h.


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