4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) YEAR YOUR_NAME <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 2003-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
8 * Copyright (C) 2008 Christian Franke <smartmontools-support@lists.sourceforge.net>
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)
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.
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.
28 PORTING NOTES AND COMMENTS
29 --------------------------
31 To port smartmontools to the OS of your choice, please:
33 [0] Contact smartmontools-support@lists.sourceforge.net to check
34 that it's not already been done.
36 [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h
39 [2] Modify configure.in so that case "${host}" includes myOS.
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
49 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
52 [4] Now that you have a working build environment, you have to
53 replace the 'stub' function calls provided in this file.
55 Provide the functions defined in this file by fleshing out the
56 skeletons below. You can entirely eliminate the function
59 [5] Contact smartmontools-support@lists.sourceforge.net to see
60 about checking your code into the smartmontools CVS archive.
64 Developer's note: for testing this file, use an unsupported system,
65 for example: ./configure --build=rs6000-ibm-aix && make
69 // This is needed for the various HAVE_* macros and PROJECT_* macros.
72 // These are needed to define prototypes and structures for the
73 // functions defined below
77 // This is to include whatever structures and prototypes you define in
79 #include "os_generic.h"
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.
85 const char *os_XXXX_c_cvsid
="$Id: os_generic.cpp 3191 2010-10-27 19:55:33Z chrfranke $" \
86 ATACMDS_H_CVSID CONFIG_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID
;
88 // This is here to prevent compiler warnings for unused arguments of
90 #define ARGUSED(x) ((void)(x))
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)
101 #include <sys/utsname.h>
104 static void unsupported(){
105 static int warninggiven
;
111 struct utsname ostype
;
113 osname
=ostype
.sysname
;
119 "############################################################################\n"
120 "WARNING: smartmontools has not been ported to the %s Operating System.\n"
121 "Please see the files os_generic.cpp and os_generic.h for porting instructions.\n"
122 "############################################################################\n\n",
129 // End of the 'unsupported()' block that you should eliminate.
132 // print examples for smartctl. You should modify this function so
133 // that the device paths are sensible for your OS, and to eliminate
134 // unsupported commands (eg, 3ware controllers).
135 static void print_smartctl_examples(){
136 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
137 #ifdef HAVE_GETOPT_LONG
139 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
140 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
141 " (Enables SMART on first disk)\n\n"
142 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
143 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
144 " (Prints Self-Test & Attribute errors)\n"
145 " smartctl -a --device=3ware,2 /dev/sda\n"
146 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
150 " smartctl -a /dev/hda (Prints all SMART information)\n"
151 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
152 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
153 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
154 " (Prints Self-Test & Attribute errors)\n"
155 " smartctl -a -d 3ware,2 /dev/sda\n"
156 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
162 /////////////////////////////////////////////////////////////////////////////
164 namespace generic
{ // No need to publish anything, name provided for Doxygen
166 class generic_smart_interface
167 : public /*implements*/ smart_interface
170 #ifdef HAVE_GET_OS_VERSION_STR
171 virtual const char * get_os_version_str();
174 virtual std::string
get_app_examples(const char * appname
);
176 virtual bool scan_smart_devices(smart_device_list
& devlist
, const char * type
,
177 const char * pattern
= 0);
180 virtual ata_device
* get_ata_device(const char * name
, const char * type
);
182 virtual scsi_device
* get_scsi_device(const char * name
, const char * type
);
184 virtual smart_device
* autodetect_smart_device(const char * name
);
186 virtual smart_device
* get_custom_smart_device(const char * name
, const char * type
);
188 virtual std::string
get_valid_custom_dev_types_str();
192 //////////////////////////////////////////////////////////////////////
194 #ifdef HAVE_GET_OS_VERSION_STR
195 /// Return build host and OS version as static string
196 const char * generic_smart_interface::get_os_version_str()
198 return ::get_os_version_str();
202 std::string
generic_smart_interface::get_app_examples(const char * appname
)
204 if (!strcmp(appname
, "smartctl"))
205 ::print_smartctl_examples(); // this prints to stdout ...
206 return ""; // ... so don't print again.
209 // Return ATA device object for the given device name or NULL
210 // the type is always set to "ata"
211 ata_device
* generic_smart_interface::get_ata_device(const char * name
, const char * type
)
220 // Return SCSI device object for the given device name or NULL
221 // the type is always set to "scsi"
222 scsi_device
* generic_smart_interface::get_scsi_device(const char * name
, const char * type
)
232 // Return device object for the given device name (autodetect the device type)
233 smart_device
* generic_smart_interface::autodetect_smart_device(const char * name
)
237 // for the given name return the apropriate device type
243 // Fill devlist with all OS's disk devices of given type that match the pattern
244 bool generic_smart_interface::scan_smart_devices(smart_device_list
& devlist
,
245 const char * type
, const char * pattern
/*= 0*/)
256 // Return device object of the given type with specified name or NULL
257 smart_device
* generic_smart_interface::get_custom_smart_device(const char * name
, const char * type
)
266 std::string
generic_smart_interface::get_valid_custom_dev_types_str()
274 /////////////////////////////////////////////////////////////////////////////
275 /// Initialize platform interface and register with smi()
277 void smart_interface::init()
279 static generic::generic_smart_interface the_interface
;
280 smart_interface::set(&the_interface
);