]>
Commit | Line | Data |
---|---|---|
832b75ed | 1 | /* |
ee38a438 | 2 | * os_generic.cpp |
832b75ed | 3 | * |
a86ec89e | 4 | * Home page of code is: http://www.smartmontools.org |
832b75ed | 5 | * |
f9e10201 JD |
6 | * Copyright (C) YEAR YOUR_NAME |
7 | * Copyright (C) 2003-8 Bruce Allen | |
ff28b140 | 8 | * Copyright (C) 2008-18 Christian Franke |
ee38a438 | 9 | * |
ff28b140 | 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
832b75ed GG |
11 | */ |
12 | ||
832b75ed | 13 | |
4d59bff9 GG |
14 | /* |
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. | |
19 | ||
20 | ||
21 | PORTING NOTES AND COMMENTS | |
22 | -------------------------- | |
23 | ||
24 | To port smartmontools to the OS of your choice, please: | |
832b75ed | 25 | |
f9e10201 | 26 | [0] Contact smartmontools-support@listi.jpberlin.de to check |
832b75ed GG |
27 | that it's not already been done. |
28 | ||
ba59cff1 GG |
29 | [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h |
30 | and os_myOS.cpp . | |
832b75ed GG |
31 | |
32 | [2] Modify configure.in so that case "${host}" includes myOS. | |
33 | ||
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 | |
40 | ... | |
41 | #endif | |
42 | where the macro HAVE_MISSINGFUNCTION is (or is not) defined in | |
43 | config.h. | |
44 | ||
ba59cff1 GG |
45 | [4] Now that you have a working build environment, you have to |
46 | replace the 'stub' function calls provided in this file. | |
47 | ||
48 | Provide the functions defined in this file by fleshing out the | |
ff28b140 | 49 | skeletons below. |
832b75ed | 50 | |
f9e10201 | 51 | [5] Contact smartmontools-support@listi.jpberlin.de to see |
832b75ed GG |
52 | about checking your code into the smartmontools CVS archive. |
53 | */ | |
54 | ||
55 | /* | |
56 | Developer's note: for testing this file, use an unsupported system, | |
57 | for example: ./configure --build=rs6000-ibm-aix && make | |
58 | */ | |
59 | ||
60 | ||
61 | // This is needed for the various HAVE_* macros and PROJECT_* macros. | |
62 | #include "config.h" | |
63 | ||
64 | // These are needed to define prototypes and structures for the | |
65 | // functions defined below | |
832b75ed | 66 | #include "atacmds.h" |
832b75ed GG |
67 | #include "utility.h" |
68 | ||
69 | // This is to include whatever structures and prototypes you define in | |
70 | // os_generic.h | |
71 | #include "os_generic.h" | |
72 | ||
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. | |
ff28b140 TL |
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; | |
832b75ed GG |
79 | |
80 | // This is here to prevent compiler warnings for unused arguments of | |
81 | // functions. | |
82 | #define ARGUSED(x) ((void)(x)) | |
83 | ||
832b75ed GG |
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). | |
2127e193 | 87 | static void print_smartctl_examples(){ |
ff28b140 | 88 | printf("=================================================== SMARTCTL EXAMPLES =====\n\n" |
832b75ed GG |
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" | |
97 | ); | |
832b75ed GG |
98 | return; |
99 | } | |
100 | ||
2127e193 GI |
101 | ///////////////////////////////////////////////////////////////////////////// |
102 | ||
103 | namespace generic { // No need to publish anything, name provided for Doxygen | |
104 | ||
105 | class generic_smart_interface | |
106 | : public /*implements*/ smart_interface | |
107 | { | |
108 | public: | |
109 | #ifdef HAVE_GET_OS_VERSION_STR | |
110 | virtual const char * get_os_version_str(); | |
111 | #endif | |
112 | ||
54965743 | 113 | virtual std::string get_app_examples(const char * appname); |
2127e193 GI |
114 | |
115 | virtual bool scan_smart_devices(smart_device_list & devlist, const char * type, | |
116 | const char * pattern = 0); | |
117 | ||
118 | protected: | |
119 | virtual ata_device * get_ata_device(const char * name, const char * type); | |
120 | ||
121 | virtual scsi_device * get_scsi_device(const char * name, const char * type); | |
122 | ||
123 | virtual smart_device * autodetect_smart_device(const char * name); | |
124 | ||
125 | virtual smart_device * get_custom_smart_device(const char * name, const char * type); | |
126 | ||
54965743 | 127 | virtual std::string get_valid_custom_dev_types_str(); |
2127e193 GI |
128 | }; |
129 | ||
130 | ||
131 | ////////////////////////////////////////////////////////////////////// | |
132 | ||
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() | |
136 | { | |
137 | return ::get_os_version_str(); | |
832b75ed | 138 | } |
2127e193 | 139 | #endif |
832b75ed | 140 | |
54965743 | 141 | std::string generic_smart_interface::get_app_examples(const char * appname) |
2127e193 GI |
142 | { |
143 | if (!strcmp(appname, "smartctl")) | |
144 | ::print_smartctl_examples(); // this prints to stdout ... | |
54965743 | 145 | return ""; // ... so don't print again. |
832b75ed GG |
146 | } |
147 | ||
2127e193 GI |
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) | |
151 | { | |
152 | ARGUSED(name); | |
832b75ed | 153 | ARGUSED(type); |
2127e193 | 154 | return NULL; |
832b75ed GG |
155 | } |
156 | ||
2127e193 GI |
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) | |
160 | { | |
161 | ARGUSED(name); | |
162 | ARGUSED(type); | |
2127e193 | 163 | return NULL; |
832b75ed GG |
164 | } |
165 | ||
2127e193 GI |
166 | |
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) | |
169 | { | |
170 | ARGUSED(name); | |
ff28b140 | 171 | // for the given name return the appropriate device type |
2127e193 | 172 | return NULL; |
832b75ed GG |
173 | } |
174 | ||
4d59bff9 | 175 | |
2127e193 GI |
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*/) | |
4d59bff9 | 179 | { |
2127e193 GI |
180 | ARGUSED(devlist); |
181 | ARGUSED(type); | |
182 | ARGUSED(pattern); | |
2127e193 | 183 | return false; |
4d59bff9 GG |
184 | } |
185 | ||
2127e193 GI |
186 | |
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) | |
189 | { | |
190 | ARGUSED(name); | |
191 | ARGUSED(type); | |
2127e193 | 192 | return NULL; |
832b75ed GG |
193 | } |
194 | ||
54965743 | 195 | std::string generic_smart_interface::get_valid_custom_dev_types_str() |
2127e193 GI |
196 | { |
197 | return ""; | |
198 | } | |
199 | ||
200 | } // namespace | |
201 | ||
202 | ||
203 | ///////////////////////////////////////////////////////////////////////////// | |
204 | /// Initialize platform interface and register with smi() | |
205 | ||
206 | void smart_interface::init() | |
207 | { | |
208 | static generic::generic_smart_interface the_interface; | |
209 | smart_interface::set(&the_interface); | |
832b75ed | 210 | } |