]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_generic.cpp
Closes #831504
[mirror_smartmontools-debian.git] / os_generic.cpp
CommitLineData
832b75ed 1/*
ee38a438 2 * os_generic.cpp
832b75ed 3 *
6b80b4d2 4 * Home page of code is: http://www.smartmontools.org
832b75ed
GG
5 *
6 * Copyright (C) YEAR YOUR_NAME <smartmontools-support@lists.sourceforge.net>
34ad0c5f 7 * Copyright (C) 2003-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
2127e193 8 * Copyright (C) 2008 Christian Franke <smartmontools-support@lists.sourceforge.net>
832b75ed
GG
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * You should have received a copy of the GNU General Public License
ee38a438
GI
16 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
17 *
832b75ed
GG
18 */
19
832b75ed 20
4d59bff9
GG
21/*
22 NOTE: The code in this file is only called when smartmontools has
23 been compiled on an unrecognized/unsupported platform. This file
24 can then serve as a "template" to make os_myOS.cpp if you wish to
25 build support for that platform.
26
27
28 PORTING NOTES AND COMMENTS
29 --------------------------
30
31 To port smartmontools to the OS of your choice, please:
832b75ed
GG
32
33 [0] Contact smartmontools-support@lists.sourceforge.net to check
34 that it's not already been done.
35
ba59cff1
GG
36 [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h
37 and os_myOS.cpp .
832b75ed
GG
38
39 [2] Modify configure.in so that case "${host}" includes myOS.
40
41 [3] Verify that ./autogen.sh && ./configure && make compiles the
42 code. If not, fix any compilation problems. If your OS lacks
43 some function that is used elsewhere in the code, then add a
44 AC_CHECK_FUNCS([missingfunction]) line to configure.in, and
45 surround uses of the function with:
46 #ifdef HAVE_MISSINGFUNCTION
47 ...
48 #endif
49 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
50 config.h.
51
ba59cff1
GG
52 [4] Now that you have a working build environment, you have to
53 replace the 'stub' function calls provided in this file.
54
55 Provide the functions defined in this file by fleshing out the
832b75ed
GG
56 skeletons below. You can entirely eliminate the function
57 'unsupported()'.
58
59 [5] Contact smartmontools-support@lists.sourceforge.net to see
60 about checking your code into the smartmontools CVS archive.
61*/
62
63/*
64 Developer's note: for testing this file, use an unsupported system,
65 for example: ./configure --build=rs6000-ibm-aix && make
66*/
67
68
69// This is needed for the various HAVE_* macros and PROJECT_* macros.
70#include "config.h"
71
72// These are needed to define prototypes and structures for the
73// functions defined below
ee38a438 74#include "int64.h"
832b75ed 75#include "atacmds.h"
832b75ed
GG
76#include "utility.h"
77
78// This is to include whatever structures and prototypes you define in
79// os_generic.h
80#include "os_generic.h"
81
82// Needed by '-V' option (CVS versioning) of smartd/smartctl. You
83// should have one *_H_CVSID macro appearing below for each file
84// appearing with #include "*.h" above. Please list these (below) in
85// alphabetic/dictionary order.
6b80b4d2 86const char * os_XXXX_cpp_cvsid="$Id: os_generic.cpp 4120 2015-08-27 16:12:21Z samm2 $"
ee38a438 87 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID;
832b75ed
GG
88
89// This is here to prevent compiler warnings for unused arguments of
90// functions.
91#define ARGUSED(x) ((void)(x))
92
93// Please eliminate the following block: both the #include and
94// the 'unsupported()' function. They are only here to warn
95// unsuspecting users that their Operating System is not supported! If
96// you wish, you can use a similar warning mechanism for any of the
97// functions in this file that you can not (or choose not to)
98// implement.
99
100
101#ifdef HAVE_UNAME
102#include <sys/utsname.h>
103#endif
104
105static void unsupported(){
106 static int warninggiven;
107
108 if (!warninggiven) {
109 char *osname;
832b75ed
GG
110
111#ifdef HAVE_UNAME
112 struct utsname ostype;
113 uname(&ostype);
114 osname=ostype.sysname;
115#else
116 osname="host's";
117#endif
118
832b75ed
GG
119 pout("\n"
120 "############################################################################\n"
121 "WARNING: smartmontools has not been ported to the %s Operating System.\n"
4d59bff9 122 "Please see the files os_generic.cpp and os_generic.h for porting instructions.\n"
832b75ed
GG
123 "############################################################################\n\n",
124 osname);
832b75ed
GG
125 warninggiven=1;
126 }
127
128 return;
129}
130// End of the 'unsupported()' block that you should eliminate.
131
132
133// print examples for smartctl. You should modify this function so
134// that the device paths are sensible for your OS, and to eliminate
135// unsupported commands (eg, 3ware controllers).
2127e193 136static void print_smartctl_examples(){
832b75ed
GG
137 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
138#ifdef HAVE_GETOPT_LONG
139 printf(
140 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
141 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
142 " (Enables SMART on first disk)\n\n"
143 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
144 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
145 " (Prints Self-Test & Attribute errors)\n"
146 " smartctl -a --device=3ware,2 /dev/sda\n"
147 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
148 );
149#else
150 printf(
151 " smartctl -a /dev/hda (Prints all SMART information)\n"
152 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
153 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
154 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
155 " (Prints Self-Test & Attribute errors)\n"
156 " smartctl -a -d 3ware,2 /dev/sda\n"
157 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
158 );
159#endif
160 return;
161}
162
2127e193
GI
163/////////////////////////////////////////////////////////////////////////////
164
165namespace generic { // No need to publish anything, name provided for Doxygen
166
167class generic_smart_interface
168: public /*implements*/ smart_interface
169{
170public:
171#ifdef HAVE_GET_OS_VERSION_STR
172 virtual const char * get_os_version_str();
173#endif
174
54965743 175 virtual std::string get_app_examples(const char * appname);
2127e193
GI
176
177 virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
178 const char * pattern = 0);
179
180protected:
181 virtual ata_device * get_ata_device(const char * name, const char * type);
182
183 virtual scsi_device * get_scsi_device(const char * name, const char * type);
184
185 virtual smart_device * autodetect_smart_device(const char * name);
186
187 virtual smart_device * get_custom_smart_device(const char * name, const char * type);
188
54965743 189 virtual std::string get_valid_custom_dev_types_str();
2127e193
GI
190};
191
192
193//////////////////////////////////////////////////////////////////////
194
195#ifdef HAVE_GET_OS_VERSION_STR
196/// Return build host and OS version as static string
197const char * generic_smart_interface::get_os_version_str()
198{
199 return ::get_os_version_str();
832b75ed 200}
2127e193 201#endif
832b75ed 202
54965743 203std::string generic_smart_interface::get_app_examples(const char * appname)
2127e193
GI
204{
205 if (!strcmp(appname, "smartctl"))
206 ::print_smartctl_examples(); // this prints to stdout ...
54965743 207 return ""; // ... so don't print again.
832b75ed
GG
208}
209
2127e193
GI
210// Return ATA device object for the given device name or NULL
211// the type is always set to "ata"
212ata_device * generic_smart_interface::get_ata_device(const char * name, const char * type)
213{
214 ARGUSED(name);
832b75ed 215 ARGUSED(type);
832b75ed 216
832b75ed 217 unsupported();
2127e193 218 return NULL;
832b75ed
GG
219}
220
2127e193
GI
221// Return SCSI device object for the given device name or NULL
222// the type is always set to "scsi"
223scsi_device * generic_smart_interface::get_scsi_device(const char * name, const char * type)
224{
225 ARGUSED(name);
226 ARGUSED(type);
227
832b75ed 228 unsupported();
2127e193 229 return NULL;
832b75ed
GG
230}
231
2127e193
GI
232
233// Return device object for the given device name (autodetect the device type)
234smart_device * generic_smart_interface::autodetect_smart_device(const char * name)
235{
236 ARGUSED(name);
237
238 // for the given name return the apropriate device type
832b75ed 239 unsupported();
2127e193 240 return NULL;
832b75ed
GG
241}
242
4d59bff9 243
2127e193
GI
244// Fill devlist with all OS's disk devices of given type that match the pattern
245bool generic_smart_interface::scan_smart_devices(smart_device_list & devlist,
246 const char * type, const char * pattern /*= 0*/)
4d59bff9 247{
2127e193
GI
248 ARGUSED(devlist);
249 ARGUSED(type);
250 ARGUSED(pattern);
251
4d59bff9 252 unsupported();
2127e193 253 return false;
4d59bff9
GG
254}
255
2127e193
GI
256
257// Return device object of the given type with specified name or NULL
258smart_device * generic_smart_interface::get_custom_smart_device(const char * name, const char * type)
259{
260 ARGUSED(name);
261 ARGUSED(type);
832b75ed
GG
262
263 unsupported();
2127e193 264 return NULL;
832b75ed
GG
265}
266
54965743 267std::string generic_smart_interface::get_valid_custom_dev_types_str()
2127e193
GI
268{
269 return "";
270}
271
272} // namespace
273
274
275/////////////////////////////////////////////////////////////////////////////
276/// Initialize platform interface and register with smi()
277
278void smart_interface::init()
279{
280 static generic::generic_smart_interface the_interface;
281 smart_interface::set(&the_interface);
832b75ed 282}