]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_generic.cpp
Refreshed patches
[mirror_smartmontools-debian.git] / os_generic.cpp
CommitLineData
832b75ed
GG
1/*
2 * os_generic.c
3 *
4 * Home page of code is: http://smartmontools.sourceforge.net
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
16 * (for example COPYING); if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
832b75ed 74#include "atacmds.h"
832b75ed
GG
75#include "utility.h"
76
77// This is to include whatever structures and prototypes you define in
78// os_generic.h
79#include "os_generic.h"
80
81// Needed by '-V' option (CVS versioning) of smartd/smartctl. You
82// should have one *_H_CVSID macro appearing below for each file
83// appearing with #include "*.h" above. Please list these (below) in
84// alphabetic/dictionary order.
54965743 85const char *os_XXXX_c_cvsid="$Id: os_generic.cpp 2915 2009-09-18 21:17:37Z chrfranke $" \
2127e193 86ATACMDS_H_CVSID CONFIG_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID;
832b75ed
GG
87
88// This is here to prevent compiler warnings for unused arguments of
89// functions.
90#define ARGUSED(x) ((void)(x))
91
92// Please eliminate the following block: both the #include and
93// the 'unsupported()' function. They are only here to warn
94// unsuspecting users that their Operating System is not supported! If
95// you wish, you can use a similar warning mechanism for any of the
96// functions in this file that you can not (or choose not to)
97// implement.
98
99
100#ifdef HAVE_UNAME
101#include <sys/utsname.h>
102#endif
103
104static void unsupported(){
105 static int warninggiven;
106
107 if (!warninggiven) {
108 char *osname;
109 extern unsigned char debugmode;
110 unsigned char savedebugmode=debugmode;
111
112#ifdef HAVE_UNAME
113 struct utsname ostype;
114 uname(&ostype);
115 osname=ostype.sysname;
116#else
117 osname="host's";
118#endif
119
120 debugmode=1;
121 pout("\n"
122 "############################################################################\n"
123 "WARNING: smartmontools has not been ported to the %s Operating System.\n"
4d59bff9 124 "Please see the files os_generic.cpp and os_generic.h for porting instructions.\n"
832b75ed
GG
125 "############################################################################\n\n",
126 osname);
127 debugmode=savedebugmode;
128 warninggiven=1;
129 }
130
131 return;
132}
133// End of the 'unsupported()' block that you should eliminate.
134
135
136// print examples for smartctl. You should modify this function so
137// that the device paths are sensible for your OS, and to eliminate
138// unsupported commands (eg, 3ware controllers).
2127e193 139static void print_smartctl_examples(){
832b75ed
GG
140 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
141#ifdef HAVE_GETOPT_LONG
142 printf(
143 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
144 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
145 " (Enables SMART on first disk)\n\n"
146 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
147 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
148 " (Prints Self-Test & Attribute errors)\n"
149 " smartctl -a --device=3ware,2 /dev/sda\n"
150 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
151 );
152#else
153 printf(
154 " smartctl -a /dev/hda (Prints all SMART information)\n"
155 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
156 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
157 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
158 " (Prints Self-Test & Attribute errors)\n"
159 " smartctl -a -d 3ware,2 /dev/sda\n"
160 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
161 );
162#endif
163 return;
164}
165
2127e193
GI
166/////////////////////////////////////////////////////////////////////////////
167
168namespace generic { // No need to publish anything, name provided for Doxygen
169
170class generic_smart_interface
171: public /*implements*/ smart_interface
172{
173public:
174#ifdef HAVE_GET_OS_VERSION_STR
175 virtual const char * get_os_version_str();
176#endif
177
54965743 178 virtual std::string get_app_examples(const char * appname);
2127e193
GI
179
180 virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
181 const char * pattern = 0);
182
183protected:
184 virtual ata_device * get_ata_device(const char * name, const char * type);
185
186 virtual scsi_device * get_scsi_device(const char * name, const char * type);
187
188 virtual smart_device * autodetect_smart_device(const char * name);
189
190 virtual smart_device * get_custom_smart_device(const char * name, const char * type);
191
54965743 192 virtual std::string get_valid_custom_dev_types_str();
2127e193
GI
193};
194
195
196//////////////////////////////////////////////////////////////////////
197
198#ifdef HAVE_GET_OS_VERSION_STR
199/// Return build host and OS version as static string
200const char * generic_smart_interface::get_os_version_str()
201{
202 return ::get_os_version_str();
832b75ed 203}
2127e193 204#endif
832b75ed 205
54965743 206std::string generic_smart_interface::get_app_examples(const char * appname)
2127e193
GI
207{
208 if (!strcmp(appname, "smartctl"))
209 ::print_smartctl_examples(); // this prints to stdout ...
54965743 210 return ""; // ... so don't print again.
832b75ed
GG
211}
212
2127e193
GI
213// Return ATA device object for the given device name or NULL
214// the type is always set to "ata"
215ata_device * generic_smart_interface::get_ata_device(const char * name, const char * type)
216{
217 ARGUSED(name);
832b75ed 218 ARGUSED(type);
832b75ed 219
832b75ed 220 unsupported();
2127e193 221 return NULL;
832b75ed
GG
222}
223
2127e193
GI
224// Return SCSI device object for the given device name or NULL
225// the type is always set to "scsi"
226scsi_device * generic_smart_interface::get_scsi_device(const char * name, const char * type)
227{
228 ARGUSED(name);
229 ARGUSED(type);
230
832b75ed 231 unsupported();
2127e193 232 return NULL;
832b75ed
GG
233}
234
2127e193
GI
235
236// Return device object for the given device name (autodetect the device type)
237smart_device * generic_smart_interface::autodetect_smart_device(const char * name)
238{
239 ARGUSED(name);
240
241 // for the given name return the apropriate device type
832b75ed 242 unsupported();
2127e193 243 return NULL;
832b75ed
GG
244}
245
4d59bff9 246
2127e193
GI
247// Fill devlist with all OS's disk devices of given type that match the pattern
248bool generic_smart_interface::scan_smart_devices(smart_device_list & devlist,
249 const char * type, const char * pattern /*= 0*/)
4d59bff9 250{
2127e193
GI
251 ARGUSED(devlist);
252 ARGUSED(type);
253 ARGUSED(pattern);
254
4d59bff9 255 unsupported();
2127e193 256 return false;
4d59bff9
GG
257}
258
2127e193
GI
259
260// Return device object of the given type with specified name or NULL
261smart_device * generic_smart_interface::get_custom_smart_device(const char * name, const char * type)
262{
263 ARGUSED(name);
264 ARGUSED(type);
832b75ed
GG
265
266 unsupported();
2127e193 267 return NULL;
832b75ed
GG
268}
269
54965743 270std::string generic_smart_interface::get_valid_custom_dev_types_str()
2127e193
GI
271{
272 return "";
273}
274
275} // namespace
276
277
278/////////////////////////////////////////////////////////////////////////////
279/// Initialize platform interface and register with smi()
280
281void smart_interface::init()
282{
283 static generic::generic_smart_interface the_interface;
284 smart_interface::set(&the_interface);
832b75ed 285}