4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) YEAR YOUR_NAME
7 * Copyright (C) 2003-8 Bruce Allen
8 * Copyright (C) 2008-18 Christian Franke
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 NOTE: The code in this file is only called when smartmontools has
16 been compiled on an unrecognized/unsupported platform. This file
17 can then serve as a "template" to make os_myOS.cpp if you wish to
18 build support for that platform.
21 PORTING NOTES AND COMMENTS
22 --------------------------
24 To port smartmontools to the OS of your choice, please:
26 [0] Contact smartmontools-support@listi.jpberlin.de to check
27 that it's not already been done.
29 [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h
32 [2] Modify configure.in so that case "${host}" includes myOS.
34 [3] Verify that ./autogen.sh && ./configure && make compiles the
35 code. If not, fix any compilation problems. If your OS lacks
36 some function that is used elsewhere in the code, then add a
37 AC_CHECK_FUNCS([missingfunction]) line to configure.in, and
38 surround uses of the function with:
39 #ifdef HAVE_MISSINGFUNCTION
42 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
45 [4] Now that you have a working build environment, you have to
46 replace the 'stub' function calls provided in this file.
48 Provide the functions defined in this file by fleshing out the
51 [5] Contact smartmontools-support@listi.jpberlin.de to see
52 about checking your code into the smartmontools CVS archive.
56 Developer's note: for testing this file, use an unsupported system,
57 for example: ./configure --build=rs6000-ibm-aix && make
61 // This is needed for the various HAVE_* macros and PROJECT_* macros.
64 // These are needed to define prototypes and structures for the
65 // functions defined below
69 // This is to include whatever structures and prototypes you define in
71 #include "os_generic.h"
73 // Needed by '-V' option (CVS versioning) of smartd/smartctl. You
74 // should have one *_H_CVSID macro appearing below for each file
75 // appearing with #include "*.h" above. Please list these (below) in
76 // alphabetic/dictionary order.
77 const char * os_XXXX_cpp_cvsid
="$Id: os_generic.cpp 4842 2018-12-02 16:07:26Z chrfranke $"
78 ATACMDS_H_CVSID CONFIG_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID
;
80 // This is here to prevent compiler warnings for unused arguments of
82 #define ARGUSED(x) ((void)(x))
84 // print examples for smartctl. You should modify this function so
85 // that the device paths are sensible for your OS, and to eliminate
86 // unsupported commands (eg, 3ware controllers).
87 static void print_smartctl_examples(){
88 printf("=================================================== SMARTCTL EXAMPLES =====\n\n"
89 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
90 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
91 " (Enables SMART on first disk)\n\n"
92 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
93 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
94 " (Prints Self-Test & Attribute errors)\n"
95 " smartctl -a --device=3ware,2 /dev/sda\n"
96 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
101 /////////////////////////////////////////////////////////////////////////////
103 namespace generic
{ // No need to publish anything, name provided for Doxygen
105 class generic_smart_interface
106 : public /*implements*/ smart_interface
109 #ifdef HAVE_GET_OS_VERSION_STR
110 virtual const char * get_os_version_str();
113 virtual std::string
get_app_examples(const char * appname
);
115 virtual bool scan_smart_devices(smart_device_list
& devlist
, const char * type
,
116 const char * pattern
= 0);
119 virtual ata_device
* get_ata_device(const char * name
, const char * type
);
121 virtual scsi_device
* get_scsi_device(const char * name
, const char * type
);
123 virtual smart_device
* autodetect_smart_device(const char * name
);
125 virtual smart_device
* get_custom_smart_device(const char * name
, const char * type
);
127 virtual std::string
get_valid_custom_dev_types_str();
131 //////////////////////////////////////////////////////////////////////
133 #ifdef HAVE_GET_OS_VERSION_STR
134 /// Return build host and OS version as static string
135 const char * generic_smart_interface::get_os_version_str()
137 return ::get_os_version_str();
141 std::string
generic_smart_interface::get_app_examples(const char * appname
)
143 if (!strcmp(appname
, "smartctl"))
144 ::print_smartctl_examples(); // this prints to stdout ...
145 return ""; // ... so don't print again.
148 // Return ATA device object for the given device name or NULL
149 // the type is always set to "ata"
150 ata_device
* generic_smart_interface::get_ata_device(const char * name
, const char * type
)
157 // Return SCSI device object for the given device name or NULL
158 // the type is always set to "scsi"
159 scsi_device
* generic_smart_interface::get_scsi_device(const char * name
, const char * type
)
167 // Return device object for the given device name (autodetect the device type)
168 smart_device
* generic_smart_interface::autodetect_smart_device(const char * name
)
171 // for the given name return the appropriate device type
176 // Fill devlist with all OS's disk devices of given type that match the pattern
177 bool generic_smart_interface::scan_smart_devices(smart_device_list
& devlist
,
178 const char * type
, const char * pattern
/*= 0*/)
187 // Return device object of the given type with specified name or NULL
188 smart_device
* generic_smart_interface::get_custom_smart_device(const char * name
, const char * type
)
195 std::string
generic_smart_interface::get_valid_custom_dev_types_str()
203 /////////////////////////////////////////////////////////////////////////////
204 /// Initialize platform interface and register with smi()
206 void smart_interface::init()
208 static generic::generic_smart_interface the_interface
;
209 smart_interface::set(&the_interface
);