]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_generic.cpp
2b9e33e0dc57650e26cdd54188fa2fcacca8eb17
[mirror_smartmontools-debian.git] / os_generic.cpp
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>
7 * Copyright (C) 2003-6 Bruce Allen <smartmontools-support@lists.sourceforge.net>
8 *
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)
12 * any later version.
13 *
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.
17 */
18
19
20 /*
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.
25
26
27 PORTING NOTES AND COMMENTS
28 --------------------------
29
30 To port smartmontools to the OS of your choice, please:
31
32 [0] Contact smartmontools-support@lists.sourceforge.net to check
33 that it's not already been done.
34
35 [1] Make copies of os_generic.[hc] called os_myOS.[hc].
36
37 [2] Modify configure.in so that case "${host}" includes myOS.
38
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
45 ...
46 #endif
47 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
48 config.h.
49
50 [4] Provide the functions defined in this file by fleshing out the
51 skeletons below. You can entirely eliminate the function
52 'unsupported()'.
53
54 [5] Contact smartmontools-support@lists.sourceforge.net to see
55 about checking your code into the smartmontools CVS archive.
56 */
57
58 /*
59 Developer's note: for testing this file, use an unsupported system,
60 for example: ./configure --build=rs6000-ibm-aix && make
61 */
62
63
64 // This is needed for the various HAVE_* macros and PROJECT_* macros.
65 #include "config.h"
66
67 // These are needed to define prototypes and structures for the
68 // functions defined below
69 #include "int64.h"
70 #include "atacmds.h"
71 #include "scsicmds.h"
72 #include "utility.h"
73
74 // This is to include whatever structures and prototypes you define in
75 // os_generic.h
76 #include "os_generic.h"
77
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;
84
85
86 // This is here to prevent compiler warnings for unused arguments of
87 // functions.
88 #define ARGUSED(x) ((void)(x))
89
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)
95 // implement.
96
97
98 #ifdef HAVE_UNAME
99 #include <sys/utsname.h>
100 #endif
101
102 static void unsupported(){
103 static int warninggiven;
104
105 if (!warninggiven) {
106 char *osname;
107 extern unsigned char debugmode;
108 unsigned char savedebugmode=debugmode;
109
110 #ifdef HAVE_UNAME
111 struct utsname ostype;
112 uname(&ostype);
113 osname=ostype.sysname;
114 #else
115 osname="host's";
116 #endif
117
118 debugmode=1;
119 pout("\n"
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",
124 osname);
125 debugmode=savedebugmode;
126 warninggiven=1;
127 }
128
129 return;
130 }
131 // End of the 'unsupported()' block that you should eliminate.
132
133
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
140 printf(
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"
149 );
150 #else
151 printf(
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"
159 );
160 #endif
161 return;
162 }
163
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) {
167 ARGUSED(dev_name);
168 unsupported();
169 return CONTROLLER_UNKNOWN;
170 }
171
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) {
179 ARGUSED(devlist);
180 ARGUSED(name);
181 unsupported();
182 return 0;
183 }
184
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){
192 ARGUSED(pathname);
193 ARGUSED(type);
194 unsupported();
195 return -1;
196 }
197
198 // Like close(). Acts only on integer handles returned by
199 // deviceopen() above.
200 int deviceclose(int fd){
201 ARGUSED(fd);
202 unsupported();
203 return 0;
204 }
205
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
211 // self-test).
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){
222 ARGUSED(fd);
223 ARGUSED(command);
224 ARGUSED(select);
225 ARGUSED(data);
226 unsupported();
227 return -1;
228 }
229
230 int marvell_command_interface(int fd, smart_command_set command, int select, char *data){
231 ARGUSED(fd);
232 ARGUSED(command);
233 ARGUSED(select);
234 ARGUSED(data);
235 unsupported();
236 return -1;
237 }
238
239
240 int highpoint_command_interface(int fd, smart_command_set command, int select, char *data)
241 {
242 ARGUSED(fd);
243 ARGUSED(command);
244 ARGUSED(select);
245 ARGUSED(data);
246 unsupported();
247 return -1;
248 }
249
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){
256 ARGUSED(fd);
257 ARGUSED(disknum);
258 ARGUSED(controller_type);
259 ARGUSED(command);
260 ARGUSED(select);
261 ARGUSED(data);
262
263 unsupported();
264 return -1;
265 }
266
267 #include <errno.h>
268 // Interface to SCSI devices. See os_linux.c
269 int do_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report) {
270 ARGUSED(fd);
271 ARGUSED(iop);
272 ARGUSED(report);
273 unsupported();
274 return -ENOSYS;
275 }