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