]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_generic.cpp
6f36aec3a3a312562ac938c60db71033931bdf1f
[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.h and os_generic.cpp called os_myOS.h
36 and os_myOS.cpp .
37
38 [2] Modify configure.in so that case "${host}" includes myOS.
39
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
46 ...
47 #endif
48 where the macro HAVE_MISSINGFUNCTION is (or is not) defined in
49 config.h.
50
51 [4] Now that you have a working build environment, you have to
52 replace the 'stub' function calls provided in this file.
53
54 Provide the functions defined in this file by fleshing out the
55 skeletons below. You can entirely eliminate the function
56 'unsupported()'.
57
58 [5] Contact smartmontools-support@lists.sourceforge.net to see
59 about checking your code into the smartmontools CVS archive.
60 */
61
62 /*
63 Developer's note: for testing this file, use an unsupported system,
64 for example: ./configure --build=rs6000-ibm-aix && make
65 */
66
67
68 // This is needed for the various HAVE_* macros and PROJECT_* macros.
69 #include "config.h"
70
71 // These are needed to define prototypes and structures for the
72 // functions defined below
73 #include "int64.h"
74 #include "atacmds.h"
75 #include "scsicmds.h"
76 #include "utility.h"
77
78 // This is to include whatever structures and prototypes you define in
79 // os_generic.h
80 #include "os_generic.h"
81
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.25 2006/10/30 18:34:30 ballen4705 Exp $" \
87 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_GENERIC_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
88
89
90 // This is here to prevent compiler warnings for unused arguments of
91 // functions.
92 #define ARGUSED(x) ((void)(x))
93
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)
99 // implement.
100
101
102 #ifdef HAVE_UNAME
103 #include <sys/utsname.h>
104 #endif
105
106 static void unsupported(){
107 static int warninggiven;
108
109 if (!warninggiven) {
110 char *osname;
111 extern unsigned char debugmode;
112 unsigned char savedebugmode=debugmode;
113
114 #ifdef HAVE_UNAME
115 struct utsname ostype;
116 uname(&ostype);
117 osname=ostype.sysname;
118 #else
119 osname="host's";
120 #endif
121
122 debugmode=1;
123 pout("\n"
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",
128 osname);
129 debugmode=savedebugmode;
130 warninggiven=1;
131 }
132
133 return;
134 }
135 // End of the 'unsupported()' block that you should eliminate.
136
137
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
144 printf(
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"
153 );
154 #else
155 printf(
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"
163 );
164 #endif
165 return;
166 }
167
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) {
171 ARGUSED(dev_name);
172 unsupported();
173 return CONTROLLER_UNKNOWN;
174 }
175
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) {
183 ARGUSED(devlist);
184 ARGUSED(name);
185 unsupported();
186 return 0;
187 }
188
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){
196 ARGUSED(pathname);
197 ARGUSED(type);
198 unsupported();
199 return -1;
200 }
201
202 // Like close(). Acts only on integer handles returned by
203 // deviceopen() above.
204 int deviceclose(int fd){
205 ARGUSED(fd);
206 unsupported();
207 return 0;
208 }
209
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
215 // self-test).
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){
226 ARGUSED(fd);
227 ARGUSED(command);
228 ARGUSED(select);
229 ARGUSED(data);
230 unsupported();
231 return -1;
232 }
233
234 int marvell_command_interface(int fd, smart_command_set command, int select, char *data){
235 ARGUSED(fd);
236 ARGUSED(command);
237 ARGUSED(select);
238 ARGUSED(data);
239 unsupported();
240 return -1;
241 }
242
243
244 int highpoint_command_interface(int fd, smart_command_set command, int select, char *data)
245 {
246 ARGUSED(fd);
247 ARGUSED(command);
248 ARGUSED(select);
249 ARGUSED(data);
250 unsupported();
251 return -1;
252 }
253
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){
260 ARGUSED(fd);
261 ARGUSED(disknum);
262 ARGUSED(controller_type);
263 ARGUSED(command);
264 ARGUSED(select);
265 ARGUSED(data);
266
267 unsupported();
268 return -1;
269 }
270
271 #include <errno.h>
272 // Interface to SCSI devices. See os_linux.c
273 int do_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report) {
274 ARGUSED(fd);
275 ARGUSED(iop);
276 ARGUSED(report);
277 unsupported();
278 return -ENOSYS;
279 }