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>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * You should have received a copy of the GNU General Public License
15 * (for example COPYING); if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 NOTE: The code in this file is only called when smartmontools has
22 been compiled on an unrecognized/unsupported platform. This file
23 can then serve as a "template" to make os_myOS.cpp if you wish to
24 build support for that platform.
27 PORTING NOTES AND COMMENTS
28 --------------------------
30 To port smartmontools to the OS of your choice, please:
32 [0] Contact smartmontools-support@lists.sourceforge.net to check
33 that it's not already been done.
35 [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h
38 [2] Modify configure.in so that case "${host}" includes myOS.
40 [3] Verify that ./autogen.sh && ./configure && make compiles the
41 code. If not, fix any compilation problems. If your OS lacks
42 some function that is used elsewhere in the code, then add a
43 AC_CHECK_FUNCS([missingfunction]) line to configure.in, and
44 surround uses of the function with:
45 #ifdef HAVE_MISSINGFUNCTION
48 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
51 [4] Now that you have a working build environment, you have to
52 replace the 'stub' function calls provided in this file.
54 Provide the functions defined in this file by fleshing out the
55 skeletons below. You can entirely eliminate the function
58 [5] Contact smartmontools-support@lists.sourceforge.net to see
59 about checking your code into the smartmontools CVS archive.
63 Developer's note: for testing this file, use an unsupported system,
64 for example: ./configure --build=rs6000-ibm-aix && make
68 // This is needed for the various HAVE_* macros and PROJECT_* macros.
71 // These are needed to define prototypes and structures for the
72 // functions defined below
78 // This is to include whatever structures and prototypes you define in
80 #include "os_generic.h"
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.
86 const char *os_XXXX_c_cvsid
="$Id: os_generic.cpp,v 1.26 2008/03/04 22:09:47 ballen4705 Exp $" \
87 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_GENERIC_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID
;
90 // This is here to prevent compiler warnings for unused arguments of
92 #define ARGUSED(x) ((void)(x))
94 // Please eliminate the following block: both the #include and
95 // the 'unsupported()' function. They are only here to warn
96 // unsuspecting users that their Operating System is not supported! If
97 // you wish, you can use a similar warning mechanism for any of the
98 // functions in this file that you can not (or choose not to)
103 #include <sys/utsname.h>
106 static void unsupported(){
107 static int warninggiven
;
111 extern unsigned char debugmode
;
112 unsigned char savedebugmode
=debugmode
;
115 struct utsname ostype
;
117 osname
=ostype
.sysname
;
124 "############################################################################\n"
125 "WARNING: smartmontools has not been ported to the %s Operating System.\n"
126 "Please see the files os_generic.cpp and os_generic.h for porting instructions.\n"
127 "############################################################################\n\n",
129 debugmode
=savedebugmode
;
135 // End of the 'unsupported()' block that you should eliminate.
138 // print examples for smartctl. You should modify this function so
139 // that the device paths are sensible for your OS, and to eliminate
140 // unsupported commands (eg, 3ware controllers).
141 void print_smartctl_examples(){
142 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
143 #ifdef HAVE_GETOPT_LONG
145 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
146 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
147 " (Enables SMART on first disk)\n\n"
148 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
149 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
150 " (Prints Self-Test & Attribute errors)\n"
151 " smartctl -a --device=3ware,2 /dev/sda\n"
152 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
156 " smartctl -a /dev/hda (Prints all SMART information)\n"
157 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
158 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
159 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
160 " (Prints Self-Test & Attribute errors)\n"
161 " smartctl -a -d 3ware,2 /dev/sda\n"
162 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
168 // tries to guess device type given the name (a path). See utility.h
169 // for return values.
170 int guess_device_type (const char* dev_name
) {
173 return CONTROLLER_UNKNOWN
;
176 // makes a list of ATA or SCSI devices for the DEVICESCAN directive of
177 // smartd. Returns number N of devices, or -1 if out of
178 // memory. Allocates N+1 arrays: one of N pointers (devlist); the
179 // other N arrays each contain null-terminated character strings. In
180 // the case N==0, no arrays are allocated because the array of 0
181 // pointers has zero length, equivalent to calling malloc(0).
182 int make_device_names (char*** devlist
, const char* name
) {
189 // Like open(). Return non-negative integer handle, only used by the
190 // functions below. type=="ATA" or "SCSI". If you need to store
191 // extra information about your devices, create a private internal
192 // array within this file (see os_freebsd.cpp for an example). If you
193 // can not open the device (permission denied, does not exist, etc)
194 // set errno as open() does and return <0.
195 int deviceopen(const char *pathname
, char *type
){
202 // Like close(). Acts only on integer handles returned by
203 // deviceopen() above.
204 int deviceclose(int fd
){
210 // Interface to ATA devices. See os_linux.cpp for the cannonical example.
211 // DETAILED DESCRIPTION OF ARGUMENTS
212 // device: is the integer handle provided by deviceopen()
213 // command: defines the different operations, see atacmds.h
214 // select: additional input data IF NEEDED (which log, which type of
216 // data: location to write output data, IF NEEDED (1 or 512 bytes).
217 // Note: not all commands use all arguments.
218 // RETURN VALUES (for all commands BUT command==STATUS_CHECK)
219 // -1 if the command failed
220 // 0 if the command succeeded,
221 // RETURN VALUES if command==STATUS_CHECK
222 // -1 if the command failed OR the disk SMART status can't be determined
223 // 0 if the command succeeded and disk SMART status is "OK"
224 // 1 if the command succeeded and disk SMART status is "FAILING"
225 int ata_command_interface(int fd
, smart_command_set command
, int select
, char *data
){
234 int marvell_command_interface(int fd
, smart_command_set command
, int select
, char *data
){
244 int highpoint_command_interface(int fd
, smart_command_set command
, int select
, char *data
)
254 // Interface to ATA devices behind 3ware escalade/apache RAID
255 // controller cards. Same description as ata_command_interface()
256 // above except that 0 <= disknum <= 15 specifies the ATA disk
257 // attached to the controller, and controller_type specifies the
258 // precise type of 3ware controller. See os_linux.c
259 int escalade_command_interface(int fd
, int disknum
, int controller_type
, smart_command_set command
, int select
, char *data
){
262 ARGUSED(controller_type
);
272 // Interface to SCSI devices. See os_linux.c
273 int do_scsi_cmnd_io(int fd
, struct scsi_cmnd_io
* iop
, int report
) {