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-6 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.[hc] called os_myOS.[hc].
37 [2] Modify configure.in so that case "${host}" includes myOS.
39 [3] Verify that ./autogen.sh && ./configure && make compiles the
40 code. If not, fix any compilation problems. If your OS lacks
41 some function that is used elsewhere in the code, then add a
42 AC_CHECK_FUNCS([missingfunction]) line to configure.in, and
43 surround uses of the function with:
44 #ifdef HAVE_MISSINGFUNCTION
47 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
50 [4] Provide the functions defined in this file by fleshing out the
51 skeletons below. You can entirely eliminate the function
54 [5] Contact smartmontools-support@lists.sourceforge.net to see
55 about checking your code into the smartmontools CVS archive.
59 Developer's note: for testing this file, use an unsupported system,
60 for example: ./configure --build=rs6000-ibm-aix && make
64 // This is needed for the various HAVE_* macros and PROJECT_* macros.
67 // These are needed to define prototypes and structures for the
68 // functions defined below
74 // This is to include whatever structures and prototypes you define in
76 #include "os_generic.h"
78 // Needed by '-V' option (CVS versioning) of smartd/smartctl. You
79 // should have one *_H_CVSID macro appearing below for each file
80 // appearing with #include "*.h" above. Please list these (below) in
81 // alphabetic/dictionary order.
82 const char *os_XXXX_c_cvsid
="$Id: os_generic.cpp,v 1.24 2006/09/20 16:17:31 shattered Exp $" \
83 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_GENERIC_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID
;
86 // This is here to prevent compiler warnings for unused arguments of
88 #define ARGUSED(x) ((void)(x))
90 // Please eliminate the following block: both the #include and
91 // the 'unsupported()' function. They are only here to warn
92 // unsuspecting users that their Operating System is not supported! If
93 // you wish, you can use a similar warning mechanism for any of the
94 // functions in this file that you can not (or choose not to)
99 #include <sys/utsname.h>
102 static void unsupported(){
103 static int warninggiven
;
107 extern unsigned char debugmode
;
108 unsigned char savedebugmode
=debugmode
;
111 struct utsname ostype
;
113 osname
=ostype
.sysname
;
120 "############################################################################\n"
121 "WARNING: smartmontools has not been ported to the %s Operating System.\n"
122 "Please see the files os_generic.cpp and os_generic.h for porting instructions.\n"
123 "############################################################################\n\n",
125 debugmode
=savedebugmode
;
131 // End of the 'unsupported()' block that you should eliminate.
134 // print examples for smartctl. You should modify this function so
135 // that the device paths are sensible for your OS, and to eliminate
136 // unsupported commands (eg, 3ware controllers).
137 void print_smartctl_examples(){
138 printf("=================================================== SMARTCTL EXAMPLES =====\n\n");
139 #ifdef HAVE_GETOPT_LONG
141 " smartctl -a /dev/hda (Prints all SMART information)\n\n"
142 " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
143 " (Enables SMART on first disk)\n\n"
144 " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n"
145 " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n"
146 " (Prints Self-Test & Attribute errors)\n"
147 " smartctl -a --device=3ware,2 /dev/sda\n"
148 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
152 " smartctl -a /dev/hda (Prints all SMART information)\n"
153 " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n"
154 " smartctl -t long /dev/hda (Executes extended disk self-test)\n"
155 " smartctl -A -l selftest -q errorsonly /dev/hda\n"
156 " (Prints Self-Test & Attribute errors)\n"
157 " smartctl -a -d 3ware,2 /dev/sda\n"
158 " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n"
164 // tries to guess device type given the name (a path). See utility.h
165 // for return values.
166 int guess_device_type (const char* dev_name
) {
169 return CONTROLLER_UNKNOWN
;
172 // makes a list of ATA or SCSI devices for the DEVICESCAN directive of
173 // smartd. Returns number N of devices, or -1 if out of
174 // memory. Allocates N+1 arrays: one of N pointers (devlist); the
175 // other N arrays each contain null-terminated character strings. In
176 // the case N==0, no arrays are allocated because the array of 0
177 // pointers has zero length, equivalent to calling malloc(0).
178 int make_device_names (char*** devlist
, const char* name
) {
185 // Like open(). Return non-negative integer handle, only used by the
186 // functions below. type=="ATA" or "SCSI". If you need to store
187 // extra information about your devices, create a private internal
188 // array within this file (see os_freebsd.cpp for an example). If you
189 // can not open the device (permission denied, does not exist, etc)
190 // set errno as open() does and return <0.
191 int deviceopen(const char *pathname
, char *type
){
198 // Like close(). Acts only on integer handles returned by
199 // deviceopen() above.
200 int deviceclose(int fd
){
206 // Interface to ATA devices. See os_linux.cpp for the cannonical example.
207 // DETAILED DESCRIPTION OF ARGUMENTS
208 // device: is the integer handle provided by deviceopen()
209 // command: defines the different operations, see atacmds.h
210 // select: additional input data IF NEEDED (which log, which type of
212 // data: location to write output data, IF NEEDED (1 or 512 bytes).
213 // Note: not all commands use all arguments.
214 // RETURN VALUES (for all commands BUT command==STATUS_CHECK)
215 // -1 if the command failed
216 // 0 if the command succeeded,
217 // RETURN VALUES if command==STATUS_CHECK
218 // -1 if the command failed OR the disk SMART status can't be determined
219 // 0 if the command succeeded and disk SMART status is "OK"
220 // 1 if the command succeeded and disk SMART status is "FAILING"
221 int ata_command_interface(int fd
, smart_command_set command
, int select
, char *data
){
230 int marvell_command_interface(int fd
, smart_command_set command
, int select
, char *data
){
240 int highpoint_command_interface(int fd
, smart_command_set command
, int select
, char *data
)
250 // Interface to ATA devices behind 3ware escalade/apache RAID
251 // controller cards. Same description as ata_command_interface()
252 // above except that 0 <= disknum <= 15 specifies the ATA disk
253 // attached to the controller, and controller_type specifies the
254 // precise type of 3ware controller. See os_linux.c
255 int escalade_command_interface(int fd
, int disknum
, int controller_type
, smart_command_set command
, int select
, char *data
){
258 ARGUSED(controller_type
);
268 // Interface to SCSI devices. See os_linux.c
269 int do_scsi_cmnd_io(int fd
, struct scsi_cmnd_io
* iop
, int report
) {