4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) 2008-16 Christian Franke
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
18 #ifndef DEV_INTERFACE_H
19 #define DEV_INTERFACE_H
21 #define DEV_INTERFACE_H_CVSID "$Id: dev_interface.h 4283 2016-04-10 12:55:59Z chrfranke $\n"
29 /////////////////////////////////////////////////////////////////////////////
30 // Common functionality for all device types
32 // Forward declarations
33 class smart_interface
;
38 /// Base class for all devices
43 /// Device info strings
47 device_info(const char * d_name
, const char * d_type
, const char * r_type
)
48 : dev_name(d_name
), info_name(d_name
),
49 dev_type(d_type
), req_type(r_type
)
52 std::string dev_name
; ///< Device (path)name
53 std::string info_name
; ///< Informal name
54 std::string dev_type
; ///< Actual device type
55 std::string req_type
; ///< Device type requested by user, empty if none
58 /// Error (number,message) pair
60 explicit error_info(int n
= 0)
62 error_info(int n
, const char * m
)
65 { no
= 0; msg
.erase(); }
67 int no
; ///< Error number
68 std::string msg
; ///< Error message
73 /// Constructor to init interface and device info.
74 /// Must be called in implementation classes.
75 smart_device(smart_interface
* intf
, const char * dev_name
,
76 const char * dev_type
, const char * req_type
);
78 /// Dummy enum for dummy constructor.
79 enum do_not_use_in_implementation_classes
{ never_called
};
80 /// Dummy constructor for abstract classes.
81 /// Must never be called in implementation classes.
82 explicit smart_device(do_not_use_in_implementation_classes
);
85 virtual ~smart_device() throw();
89 ///////////////////////////////////////////////
90 // Dynamic downcasts to actual device flavor
92 /// Return true if ATA device
94 { return !!m_ata_ptr
; }
95 /// Return true if SCSI device
97 { return !!m_scsi_ptr
; }
98 /// Return true if NVMe device
100 { return !!m_nvme_ptr
; }
102 /// Downcast to ATA device.
103 ata_device
* to_ata()
104 { return m_ata_ptr
; }
105 /// Downcast to ATA device (const).
106 const ata_device
* to_ata() const
107 { return m_ata_ptr
; }
108 /// Downcast to SCSI device.
109 scsi_device
* to_scsi()
110 { return m_scsi_ptr
; }
111 /// Downcast to SCSI device (const).
112 const scsi_device
* to_scsi() const
113 { return m_scsi_ptr
; }
114 /// Downcast to NVMe device.
115 nvme_device
* to_nvme()
116 { return m_nvme_ptr
; }
117 /// Downcast to NVMe device (const).
118 const nvme_device
* to_nvme() const
119 { return m_nvme_ptr
; }
121 ///////////////////////////////////////////////
122 // Device information
124 /// Get device info struct.
125 const device_info
& get_info() const
128 /// Get device (path)name.
129 const char * get_dev_name() const
130 { return m_info
.dev_name
.c_str(); }
131 /// Get informal name.
132 const char * get_info_name() const
133 { return m_info
.info_name
.c_str(); }
135 const char * get_dev_type() const
136 { return m_info
.dev_type
.c_str(); }
137 /// Get type requested by user, empty if none.
138 const char * get_req_type() const
139 { return m_info
.req_type
.c_str(); }
142 /// R/W access to device info struct.
143 device_info
& set_info()
147 ///////////////////////////////////////////////
148 // Last error information
150 /// Get last error info struct.
151 const error_info
& get_err() const
153 /// Get last error number.
154 int get_errno() const
156 /// Get last error message.
157 const char * get_errmsg() const
158 { return m_err
.msg
.c_str(); }
160 /// Return true if last error indicates an unsupported system call.
161 /// Default implementation returns true on ENOSYS and ENOTSUP.
162 virtual bool is_syscall_unsup() const;
164 /// Set last error number and message.
165 /// Printf()-like formatting is supported.
166 /// Returns false always to allow use as a return expression.
167 bool set_err(int no
, const char * msg
, ...)
168 __attribute_format_printf(3, 4);
170 /// Set last error info struct.
171 bool set_err(const error_info
& err
)
172 { m_err
= err
; return false; }
174 /// Clear last error info.
178 /// Set last error number and default message.
179 /// Message is retrieved from interface's get_msg_for_errno(no).
180 bool set_err(int no
);
182 /// Get current number of allocated 'smart_device' objects.
183 static int get_num_objects()
184 { return s_num_objects
; }
188 ///////////////////////////////////////////////
190 // Must be implemented in derived class
192 /// Return true if device is open.
193 virtual bool is_open() const = 0;
195 /// Open device, return false on error.
196 virtual bool open() = 0;
198 /// Close device, return false on error.
199 virtual bool close() = 0;
201 /// Open device with autodetection support.
202 /// May return another device for further access.
203 /// In this case, the original pointer is no longer valid.
204 /// Default implementation calls 'open()' and returns 'this'.
205 virtual smart_device
* autodetect_open();
207 ///////////////////////////////////////////////
208 // Support for checking power mode reported by operating system
210 /// Early test if device is powered up or down.
211 /// Can be used without calling 'open()' first!
212 /// Return true when device is powered down, false when
213 /// powered up. If this function is not implemented or
214 /// the mode cannot be determined, return false.
215 /// Default implementation returns false.
216 virtual bool is_powered_down();
218 ///////////////////////////////////////////////
219 // Support for tunnelled devices
221 /// Return true if other device is owned by this device.
222 /// Default implementation returns false.
223 virtual bool owns(const smart_device
* dev
) const;
225 /// Release ownership of other device.
226 /// Default implementation does nothing.
227 virtual void release(const smart_device
* dev
);
230 /// Get interface which produced this object.
231 smart_interface
* smi()
233 /// Get interface which produced this object (const).
234 const smart_interface
* smi() const
239 smart_interface
* m_intf
;
243 // Pointers for to_ata(), to_scsi(), to_nvme()
244 // set by ATA/SCSI/NVMe interface classes.
245 friend class ata_device
;
246 ata_device
* m_ata_ptr
;
247 friend class scsi_device
;
248 scsi_device
* m_scsi_ptr
;
249 friend class nvme_device
;
250 nvme_device
* m_nvme_ptr
;
252 // Number of objects.
253 static int s_num_objects
;
255 // Prevent copy/assigment
256 smart_device(const smart_device
&);
257 void operator=(const smart_device
&);
261 /////////////////////////////////////////////////////////////////////////////
262 // ATA specific interface
264 /// ATA register value and info whether it has ever been set
265 // (Automatically set by first assignment)
270 : m_val(0x00), m_is_set(false) { }
272 ata_register
& operator=(unsigned char x
)
273 { m_val
= x
; m_is_set
= true; return * this; }
275 unsigned char val() const
277 operator unsigned char() const
284 unsigned char m_val
; ///< Register value
285 bool m_is_set
; ///< true if set
288 /// ATA Input registers (for 28-bit commands)
291 // ATA-6/7 register names // ATA-3/4/5 // ATA-8
292 ata_register features
; // features // features
293 ata_register sector_count
; // sector count // count
294 ata_register lba_low
; // sector number // ]
295 ata_register lba_mid
; // cylinder low // ] lba
296 ata_register lba_high
; // cylinder high // ]
297 ata_register device
; // device/head // device
298 ata_register command
; // command // command
300 /// Return true if any register is set
302 { return (features
.is_set() || sector_count
.is_set()
303 || lba_low
.is_set() || lba_mid
.is_set() || lba_high
.is_set()
304 || device
.is_set() || command
.is_set()); }
307 /// ATA Output registers (for 28-bit commands)
311 ata_register sector_count
;
312 ata_register lba_low
;
313 ata_register lba_mid
;
314 ata_register lba_high
;
318 /// Return true if any register is set
320 { return (error
.is_set() || sector_count
.is_set()
321 || lba_low
.is_set() || lba_mid
.is_set() || lba_high
.is_set()
322 || device
.is_set() || status
.is_set()); }
326 /// 16-bit alias to a 8-bit ATA register pair.
327 class ata_reg_alias_16
330 ata_reg_alias_16(ata_register
& lo
, ata_register
& hi
)
331 : m_lo(lo
), m_hi(hi
) { }
333 ata_reg_alias_16
& operator=(unsigned short x
)
334 { m_lo
= (unsigned char) x
;
335 m_hi
= (unsigned char)(x
>> 8);
338 unsigned short val() const
339 { return m_lo
| (m_hi
<< 8); }
340 operator unsigned short() const
341 { return m_lo
| (m_hi
<< 8); }
344 ata_register
& m_lo
, & m_hi
;
346 // References must not be copied.
347 ata_reg_alias_16(const ata_reg_alias_16
&);
348 void operator=(const ata_reg_alias_16
&);
352 /// 48-bit alias to six 8-bit ATA registers (for LBA).
353 class ata_reg_alias_48
356 ata_reg_alias_48(ata_register
& ll
, ata_register
& lm
, ata_register
& lh
,
357 ata_register
& hl
, ata_register
& hm
, ata_register
& hh
)
358 : m_ll(ll
), m_lm(lm
), m_lh(lh
),
359 m_hl(hl
), m_hm(hm
), m_hh(hh
)
362 ata_reg_alias_48
& operator=(uint64_t x
)
364 m_ll
= (unsigned char) x
;
365 m_lm
= (unsigned char)(x
>> 8);
366 m_lh
= (unsigned char)(x
>> 16);
367 m_hl
= (unsigned char)(x
>> 24);
368 m_hm
= (unsigned char)(x
>> 32);
369 m_hh
= (unsigned char)(x
>> 40);
375 return ( (unsigned)m_ll
376 | ((unsigned)m_lm
<< 8)
377 | ((unsigned)m_lh
<< 16)
378 | ((unsigned)m_hl
<< 24)
379 | ((uint64_t)m_hm
<< 32)
380 | ((uint64_t)m_hh
<< 40));
383 operator uint64_t() const
387 ata_register
& m_ll
, & m_lm
, & m_lh
,
388 & m_hl
, & m_hm
, & m_hh
;
390 // References must not be copied.
391 ata_reg_alias_48(const ata_reg_alias_48
&);
392 void operator=(const ata_reg_alias_48
&);
396 /// ATA Input registers for 48-bit commands
397 // See section 4.14 of T13/1532D Volume 1 Revision 4b
399 // Uses ATA-6/7 method to specify 16-bit registers as
400 // recent (low byte) and previous (high byte) content of
403 // (ATA-8 ACS does not longer follow this scheme, it uses
404 // abstract registers with sufficient size and leaves the
405 // actual mapping to the transport layer.)
407 struct ata_in_regs_48bit
408 : public ata_in_regs
// "most recently written" registers
410 ata_in_regs prev
; ///< "previous content"
412 // 16-bit aliases for above pair.
413 ata_reg_alias_16 features_16
;
414 ata_reg_alias_16 sector_count_16
;
415 ata_reg_alias_16 lba_low_16
;
416 ata_reg_alias_16 lba_mid_16
;
417 ata_reg_alias_16 lba_high_16
;
419 // 48-bit alias to all 8-bit LBA registers.
420 ata_reg_alias_48 lba_48
;
422 /// Return true if 48-bit command
423 bool is_48bit_cmd() const
424 { return prev
.is_set(); }
426 /// Return true if 48-bit command with any nonzero high byte
427 bool is_real_48bit_cmd() const
428 { return ( prev
.features
|| prev
.sector_count
429 || prev
.lba_low
|| prev
.lba_mid
|| prev
.lba_high
); }
435 /// ATA Output registers for 48-bit commands
436 struct ata_out_regs_48bit
437 : public ata_out_regs
// read with HOB=0
439 ata_out_regs prev
; ///< read with HOB=1
441 // 16-bit aliases for above pair.
442 ata_reg_alias_16 sector_count_16
;
443 ata_reg_alias_16 lba_low_16
;
444 ata_reg_alias_16 lba_mid_16
;
445 ata_reg_alias_16 lba_high_16
;
447 // 48-bit alias to all 8-bit LBA registers.
448 ata_reg_alias_48 lba_48
;
450 ata_out_regs_48bit();
454 /// Flags for each ATA output register
455 struct ata_out_regs_flags
457 bool error
, sector_count
, lba_low
, lba_mid
, lba_high
, device
, status
;
459 /// Return true if any flag is set.
461 { return ( error
|| sector_count
|| lba_low
462 || lba_mid
|| lba_high
|| device
|| status
); }
464 /// Default constructor clears all flags.
466 : error(false), sector_count(false), lba_low(false), lba_mid(false),
467 lba_high(false), device(false), status(false) { }
471 /// ATA pass through input parameters
474 ata_in_regs_48bit in_regs
; ///< Input registers
475 ata_out_regs_flags out_needed
; ///< True if output register value needed
476 enum { no_data
= 0, data_in
, data_out
} direction
; ///< I/O direction
477 void * buffer
; ///< Pointer to data buffer
478 unsigned size
; ///< Size of buffer
480 /// Prepare for 28-bit DATA IN command
481 void set_data_in(void * buf
, unsigned nsectors
)
484 in_regs
.sector_count
= nsectors
;
486 size
= nsectors
* 512;
489 /// Prepare for 28-bit DATA OUT command
490 void set_data_out(const void * buf
, unsigned nsectors
)
492 buffer
= const_cast<void *>(buf
);
493 in_regs
.sector_count
= nsectors
;
494 direction
= data_out
;
495 size
= nsectors
* 512;
498 /// Prepare for 48-bit DATA IN command
499 void set_data_in_48bit(void * buf
, unsigned nsectors
)
502 // Note: This also sets 'in_regs.is_48bit_cmd()'
503 in_regs
.sector_count_16
= nsectors
;
505 size
= nsectors
* 512;
511 /// ATA pass through output parameters
514 ata_out_regs_48bit out_regs
; ///< Output registers
519 /// ATA device access
521 : virtual public /*extends*/ smart_device
524 /// ATA pass through.
525 /// Return false on error.
526 /// Must be implemented in derived class.
527 virtual bool ata_pass_through(const ata_cmd_in
& in
, ata_cmd_out
& out
) = 0;
529 /// ATA pass through without output registers.
530 /// Return false on error.
531 /// Calls ata_pass_through(in, dummy), cannot be reimplemented.
532 bool ata_pass_through(const ata_cmd_in
& in
);
534 /// Return true if OS caches ATA identify sector.
535 /// Default implementation returns false.
536 virtual bool ata_identify_is_cached() const;
539 /// Flags for ata_cmd_is_supported().
541 supports_data_out
= 0x01, // PIO DATA OUT
542 supports_smart_status
= 0x02, // read output registers for SMART STATUS only
543 supports_output_regs
= 0x04, // read output registers for all commands
544 supports_multi_sector
= 0x08, // more than one sector (1 DRQ/sector variant)
545 supports_48bit_hi_null
= 0x10, // 48-bit commands with null high bytes only
546 supports_48bit
= 0x20, // all 48-bit commands
549 /// Check command input parameters.
550 /// Return false if required features are not implemented.
551 /// Calls set_err(...) accordingly.
552 bool ata_cmd_is_supported(const ata_cmd_in
& in
, unsigned flags
,
553 const char * type
= 0);
555 /// Check command input parameters (old version).
556 // TODO: Remove if no longer used.
557 bool ata_cmd_is_ok(const ata_cmd_in
& in
,
558 bool data_out_support
= false,
559 bool multi_sector_support
= false,
560 bool ata_48bit_support
= false)
562 return ata_cmd_is_supported(in
,
563 (data_out_support
? supports_data_out
: 0) |
564 supports_output_regs
|
565 (multi_sector_support
? supports_multi_sector
: 0) |
566 (ata_48bit_support
? supports_48bit
: 0));
569 /// Hide/unhide ATA interface.
570 void hide_ata(bool hide
= true)
571 { m_ata_ptr
= (!hide
? this : 0); }
573 /// Default constructor, registers device as ATA.
575 : smart_device(never_called
)
580 /////////////////////////////////////////////////////////////////////////////
581 // SCSI specific interface
585 /// SCSI device access
587 : virtual public /*extends*/ smart_device
590 /// SCSI pass through.
591 /// Returns false on error.
592 virtual bool scsi_pass_through(scsi_cmnd_io
* iop
) = 0;
595 /// Hide/unhide SCSI interface.
596 void hide_scsi(bool hide
= true)
597 { m_scsi_ptr
= (!hide
? this : 0); }
599 /// Default constructor, registers device as SCSI.
601 : smart_device(never_called
)
602 { hide_scsi(false); }
606 /////////////////////////////////////////////////////////////////////////////
607 // NVMe specific interface
609 /// NVMe pass through input parameters
612 unsigned char opcode
; ///< Opcode (CDW0 07:00)
613 unsigned nsid
; ///< Namespace ID
614 unsigned cdw10
, cdw11
, cdw12
, cdw13
, cdw14
, cdw15
; ///< Cmd specific
616 void * buffer
; ///< Pointer to data buffer
617 unsigned size
; ///< Size of buffer
620 no_data
= 0x0, data_out
= 0x1, data_in
= 0x2, data_io
= 0x3
623 /// Get I/O direction from opcode
624 unsigned char direction() const
625 { return (opcode
& 0x3); }
627 // Prepare for DATA IN command
628 void set_data_in(unsigned char op
, void * buf
, unsigned sz
)
631 if (direction() != data_in
)
632 throw std::logic_error("invalid opcode for DATA IN");
638 : opcode(0), nsid(0),
639 cdw10(0), cdw11(0), cdw12(0), cdw13(0), cdw14(0), cdw15(0),
644 /// NVMe pass through output parameters
647 unsigned result
; ///< Command specific result (DW0)
648 unsigned short status
; ///< Status Field (DW3 31:17)
649 bool status_valid
; ///< true if status is valid
652 : result(0), status(0), status_valid(false)
656 /// NVMe device access
658 : virtual public /*extends*/ smart_device
661 /// NVMe pass through.
662 /// Return false on error.
663 virtual bool nvme_pass_through(const nvme_cmd_in
& in
, nvme_cmd_out
& out
) = 0;
665 /// Get namespace id.
666 unsigned get_nsid() const
670 /// Hide/unhide NVMe interface.
671 void hide_nvme(bool hide
= true)
672 { m_nvme_ptr
= (!hide
? this : 0); }
674 /// Constructor requires namespace ID, registers device as NVMe.
675 explicit nvme_device(unsigned nsid
)
676 : smart_device(never_called
),
678 { hide_nvme(false); }
680 /// Set namespace id.
681 /// Should be called in open() function if get_nsid() returns 0.
682 void set_nsid(unsigned nsid
)
685 /// Set last error number and message if pass-through returns NVMe error status.
686 /// Returns false always to allow use as a return expression.
687 bool set_nvme_err(nvme_cmd_out
& out
, unsigned status
, const char * msg
= 0);
694 /////////////////////////////////////////////////////////////////////////////
695 /// Smart pointer class for device pointers
698 class any_device_auto_ptr
701 typedef Dev device_type
;
703 /// Construct from optional pointer to device
704 /// and optional pointer to base device.
705 explicit any_device_auto_ptr(device_type
* dev
= 0,
706 smart_device
* base_dev
= 0)
707 : m_dev(dev
), m_base_dev(base_dev
) { }
709 /// Destructor deletes device object.
710 ~any_device_auto_ptr() throw()
713 /// Assign a new pointer.
714 /// Throws if a pointer is already assigned.
715 void operator=(device_type
* dev
)
722 /// Delete device object and clear the pointer.
726 if (m_base_dev
&& m_dev
->owns(m_base_dev
))
727 m_dev
->release(m_base_dev
);
733 /// Return the pointer and release ownership.
734 device_type
* release()
736 device_type
* dev
= m_dev
;
741 /// Replace the pointer.
742 /// Used to call dev->autodetect_open().
743 void replace(device_type
* dev
)
746 /// Return the pointer.
747 device_type
* get() const
750 /// Pointer dereferencing.
751 device_type
& operator*() const
754 /// Pointer dereferencing.
755 device_type
* operator->() const
758 /// For (ptr != 0) check.
759 operator bool() const
762 /// For (ptr == 0) check.
763 bool operator !() const
768 smart_device
* m_base_dev
;
771 { throw std::logic_error("any_device_auto_ptr: wrong usage"); }
773 // Prevent copy/assignment
774 any_device_auto_ptr(const any_device_auto_ptr
<Dev
> &);
775 void operator=(const any_device_auto_ptr
<Dev
> &);
778 typedef any_device_auto_ptr
<smart_device
> smart_device_auto_ptr
;
779 typedef any_device_auto_ptr
<ata_device
> ata_device_auto_ptr
;
780 typedef any_device_auto_ptr
<scsi_device
> scsi_device_auto_ptr
;
781 typedef any_device_auto_ptr
<nvme_device
> nvme_device_auto_ptr
;
784 /////////////////////////////////////////////////////////////////////////////
787 /// List of devices for DEVICESCAN
788 class smart_device_list
795 ~smart_device_list() throw()
797 for (unsigned i
= 0; i
< m_list
.size(); i
++)
802 unsigned size() const
803 { return m_list
.size(); }
808 for (unsigned i
= 0; i
< m_list
.size(); i
++)
814 void push_back(smart_device
* dev
)
815 { m_list
.push_back(dev
); }
817 void push_back(smart_device_auto_ptr
& dev
)
819 m_list
.push_back(dev
.get());
823 smart_device
* at(unsigned i
)
824 { return m_list
.at(i
); }
826 const smart_device
* at(unsigned i
) const
827 { return m_list
.at(i
); }
829 smart_device
* release(unsigned i
)
831 smart_device
* dev
= m_list
.at(i
);
836 void append(smart_device_list
& devlist
)
838 for (unsigned i
= 0; i
< devlist
.size(); i
++) {
839 smart_device
* dev
= devlist
.at(i
);
843 devlist
.m_list
.at(i
) = 0;
849 std::vector
<smart_device
*> m_list
;
851 // Prevent copy/assigment
852 smart_device_list(const smart_device_list
&);
853 void operator=(const smart_device_list
&);
857 /// List of types for DEVICESCAN
858 typedef std::vector
<std::string
> smart_devtype_list
;
861 /////////////////////////////////////////////////////////////////////////////
864 /// The platform interface abstraction
865 class smart_interface
868 /// Initialize platform interface and register with smi().
869 /// Must be implemented by platform module and register interface with set()
875 virtual ~smart_interface() throw()
878 /// Return info string about build host and/or OS version.
879 /// Default implementation returns SMARTMONTOOLS_BUILD_HOST.
880 virtual std::string
get_os_version_str();
882 /// Return valid args for device type option/directive.
883 /// Default implementation returns "ata, scsi, sat, usb*..."
884 /// concatenated with result from get_valid_custom_dev_types_str().
885 virtual std::string
get_valid_dev_types_str();
887 /// Return example string for program 'appname'.
888 /// Default implementation returns empty string.
889 /// For the migration of print_smartctl_examples(),
890 /// function is allowed to print examples to stdout.
891 /// TODO: Remove this hack.
892 virtual std::string
get_app_examples(const char * appname
);
894 /// Get microseconds since some unspecified starting point.
895 /// Used only for command duration measurements in debug outputs.
896 /// Returns -1 if unsupported.
897 /// Default implementation uses clock_gettime(), gettimeofday() or ftime().
898 virtual int64_t get_timer_usec();
900 /// Disable/Enable system auto standby/sleep mode.
901 /// Return false if unsupported or if system is running
903 /// Default implementation returns false.
904 virtual bool disable_system_auto_standby(bool disable
);
907 ///////////////////////////////////////////////
908 // Last error information
910 /// Get last error info struct.
911 const smart_device::error_info
& get_err() const
913 /// Get last error number.
914 int get_errno() const
916 /// Get last error message.
917 const char * get_errmsg() const
918 { return m_err
.msg
.c_str(); }
920 /// Set last error number and message.
921 /// Printf()-like formatting is supported.
922 /// Returns false always to allow use as a return expression.
923 bool set_err(int no
, const char * msg
, ...)
924 __attribute_format_printf(3, 4);
926 /// Set last error info struct.
927 bool set_err(const smart_device::error_info
& err
)
928 { m_err
= err
; return false; }
930 /// Clear last error info.
934 /// Set last error number and default message.
935 /// Message is retrieved from get_msg_for_errno(no).
936 bool set_err(int no
);
938 /// Set last error number and default message to any error_info.
939 /// Used by set_err(no).
940 bool set_err_var(smart_device::error_info
* err
, int no
);
942 /// Convert error number into message, used by set_err(no).
943 /// Default implementation returns strerror(no).
944 virtual const char * get_msg_for_errno(int no
);
946 ///////////////////////////////////////////////////////////////////////////
949 /// Return device object for device 'name' with some 'type'.
950 /// 'type' is 0 if not specified by user.
951 /// Return 0 on error.
952 /// Default implementation selects between ata, scsi and custom device.
953 virtual smart_device
* get_smart_device(const char * name
, const char * type
);
955 /// Fill 'devlist' with devices of some 'type' with device names
956 /// specified by some optional 'pattern'.
957 /// Use platform specific default if 'type' is empty or 0.
958 /// Return false on error.
959 virtual bool scan_smart_devices(smart_device_list
& devlist
, const char * type
,
960 const char * pattern
= 0) = 0;
962 /// Fill 'devlist' with devices of all 'types' with device names
963 /// specified by some optional 'pattern'.
964 /// Use platform specific default if 'types' is empty.
965 /// Return false on error.
966 /// Default implementation calls above function for all types
967 /// and concatenates the results.
968 virtual bool scan_smart_devices(smart_device_list
& devlist
,
969 const smart_devtype_list
& types
, const char * pattern
= 0);
972 /// Return standard ATA device.
973 virtual ata_device
* get_ata_device(const char * name
, const char * type
) = 0;
975 /// Return standard SCSI device.
976 virtual scsi_device
* get_scsi_device(const char * name
, const char * type
) = 0;
978 /// Return standard NVMe device.
979 /// Default implementation returns 0.
980 virtual nvme_device
* get_nvme_device(const char * name
, const char * type
,
983 /// Autodetect device if no device type specified.
984 virtual smart_device
* autodetect_smart_device(const char * name
) = 0;
986 /// Return device for platform specific 'type'.
987 /// Default implementation returns 0.
988 virtual smart_device
* get_custom_smart_device(const char * name
, const char * type
);
990 /// Return valid 'type' args accepted by above.
991 /// This is called in get_valid_dev_types_str().
992 /// Default implementation returns empty string.
993 virtual std::string
get_valid_custom_dev_types_str();
995 /// Return ATA->SCSI filter for a SAT or USB 'type'.
996 /// Device 'scsidev' is used for SCSI access.
997 /// Return 0 and delete 'scsidev' on error.
998 /// Override only if platform needs special handling.
999 virtual ata_device
* get_sat_device(const char * type
, scsi_device
* scsidev
);
1000 //{ implemented in scsiata.cpp }
1003 /// Try to detect a SAT device behind a SCSI interface.
1004 /// Inquiry data can be passed if available.
1005 /// Return appropriate device if yes, otherwise 0.
1006 /// Override only if platform needs special handling.
1007 virtual ata_device
* autodetect_sat_device(scsi_device
* scsidev
,
1008 const unsigned char * inqdata
, unsigned inqsize
);
1009 //{ implemented in scsiata.cpp }
1011 /// Get type name for USB device with known VENDOR:PRODUCT ID.
1012 /// Return name if device known and supported, otherwise 0.
1013 virtual const char * get_usb_dev_type_by_id(int vendor_id
, int product_id
,
1015 //{ implemented in scsiata.cpp }
1018 /// Set interface to use, must be called from init().
1019 static void set(smart_interface
* intf
)
1020 { s_instance
= intf
; }
1024 smart_device::error_info m_err
;
1026 friend smart_interface
* smi(); // below
1027 static smart_interface
* s_instance
; ///< Pointer to the interface object.
1029 // Prevent copy/assigment
1030 smart_interface(const smart_interface
&);
1031 void operator=(const smart_interface
&);
1035 /////////////////////////////////////////////////////////////////////////////
1038 /// Global access to the (usually singleton) smart_interface
1039 inline smart_interface
* smi()
1040 { return smart_interface::s_instance
; }
1042 /////////////////////////////////////////////////////////////////////////////
1044 #endif // DEV_INTERFACE_H