]>
Commit | Line | Data |
---|---|---|
832b75ed GG |
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 | /* PORTING NOTES AND COMMENTS | |
20 | ||
21 | To port smartmontools to the OS of your choice, please: | |
22 | ||
23 | [0] Contact smartmontools-support@lists.sourceforge.net to check | |
24 | that it's not already been done. | |
25 | ||
26 | [1] Make copies of os_generic.[hc] called os_myOS.[hc]. | |
27 | ||
28 | [2] Modify configure.in so that case "${host}" includes myOS. | |
29 | ||
30 | [3] Verify that ./autogen.sh && ./configure && make compiles the | |
31 | code. If not, fix any compilation problems. If your OS lacks | |
32 | some function that is used elsewhere in the code, then add a | |
33 | AC_CHECK_FUNCS([missingfunction]) line to configure.in, and | |
34 | surround uses of the function with: | |
35 | #ifdef HAVE_MISSINGFUNCTION | |
36 | ... | |
37 | #endif | |
38 | where the macro HAVE_MISSINGFUNCTION is (or is not) defined in | |
39 | config.h. | |
40 | ||
41 | [4] Provide the functions defined in this file by fleshing out the | |
42 | skeletons below. You can entirely eliminate the function | |
43 | 'unsupported()'. | |
44 | ||
45 | [5] Contact smartmontools-support@lists.sourceforge.net to see | |
46 | about checking your code into the smartmontools CVS archive. | |
47 | */ | |
48 | ||
49 | /* | |
50 | Developer's note: for testing this file, use an unsupported system, | |
51 | for example: ./configure --build=rs6000-ibm-aix && make | |
52 | */ | |
53 | ||
54 | ||
55 | // This is needed for the various HAVE_* macros and PROJECT_* macros. | |
56 | #include "config.h" | |
57 | ||
58 | // These are needed to define prototypes and structures for the | |
59 | // functions defined below | |
60 | #include "int64.h" | |
61 | #include "atacmds.h" | |
62 | #include "scsicmds.h" | |
63 | #include "utility.h" | |
64 | ||
65 | // This is to include whatever structures and prototypes you define in | |
66 | // os_generic.h | |
67 | #include "os_generic.h" | |
68 | ||
69 | // Needed by '-V' option (CVS versioning) of smartd/smartctl. You | |
70 | // should have one *_H_CVSID macro appearing below for each file | |
71 | // appearing with #include "*.h" above. Please list these (below) in | |
72 | // alphabetic/dictionary order. | |
73 | const char *os_XXXX_c_cvsid="$Id: os_generic.c,v 1.21 2006/04/12 14:54:28 ballen4705 Exp $" \ | |
74 | ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_GENERIC_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; | |
75 | ||
76 | ||
77 | // This is here to prevent compiler warnings for unused arguments of | |
78 | // functions. | |
79 | #define ARGUSED(x) ((void)(x)) | |
80 | ||
81 | // Please eliminate the following block: both the #include and | |
82 | // the 'unsupported()' function. They are only here to warn | |
83 | // unsuspecting users that their Operating System is not supported! If | |
84 | // you wish, you can use a similar warning mechanism for any of the | |
85 | // functions in this file that you can not (or choose not to) | |
86 | // implement. | |
87 | ||
88 | ||
89 | #ifdef HAVE_UNAME | |
90 | #include <sys/utsname.h> | |
91 | #endif | |
92 | ||
93 | static void unsupported(){ | |
94 | static int warninggiven; | |
95 | ||
96 | if (!warninggiven) { | |
97 | char *osname; | |
98 | extern unsigned char debugmode; | |
99 | unsigned char savedebugmode=debugmode; | |
100 | ||
101 | #ifdef HAVE_UNAME | |
102 | struct utsname ostype; | |
103 | uname(&ostype); | |
104 | osname=ostype.sysname; | |
105 | #else | |
106 | osname="host's"; | |
107 | #endif | |
108 | ||
109 | debugmode=1; | |
110 | pout("\n" | |
111 | "############################################################################\n" | |
112 | "WARNING: smartmontools has not been ported to the %s Operating System.\n" | |
113 | "Please see the files os_generic.c and os_generic.h for porting instructions.\n" | |
114 | "############################################################################\n\n", | |
115 | osname); | |
116 | debugmode=savedebugmode; | |
117 | warninggiven=1; | |
118 | } | |
119 | ||
120 | return; | |
121 | } | |
122 | // End of the 'unsupported()' block that you should eliminate. | |
123 | ||
124 | ||
125 | // print examples for smartctl. You should modify this function so | |
126 | // that the device paths are sensible for your OS, and to eliminate | |
127 | // unsupported commands (eg, 3ware controllers). | |
128 | void print_smartctl_examples(){ | |
129 | printf("=================================================== SMARTCTL EXAMPLES =====\n\n"); | |
130 | #ifdef HAVE_GETOPT_LONG | |
131 | printf( | |
132 | " smartctl -a /dev/hda (Prints all SMART information)\n\n" | |
133 | " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n" | |
134 | " (Enables SMART on first disk)\n\n" | |
135 | " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n" | |
136 | " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n" | |
137 | " (Prints Self-Test & Attribute errors)\n" | |
138 | " smartctl -a --device=3ware,2 /dev/sda\n" | |
139 | " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n" | |
140 | ); | |
141 | #else | |
142 | printf( | |
143 | " smartctl -a /dev/hda (Prints all SMART information)\n" | |
144 | " smartctl -s on -o on -S on /dev/hda (Enables SMART on first disk)\n" | |
145 | " smartctl -t long /dev/hda (Executes extended disk self-test)\n" | |
146 | " smartctl -A -l selftest -q errorsonly /dev/hda\n" | |
147 | " (Prints Self-Test & Attribute errors)\n" | |
148 | " smartctl -a -d 3ware,2 /dev/sda\n" | |
149 | " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n" | |
150 | ); | |
151 | #endif | |
152 | return; | |
153 | } | |
154 | ||
155 | // tries to guess device type given the name (a path). See utility.h | |
156 | // for return values. | |
157 | int guess_device_type (const char* dev_name) { | |
158 | ARGUSED(dev_name); | |
159 | unsupported(); | |
160 | return CONTROLLER_UNKNOWN; | |
161 | } | |
162 | ||
163 | // makes a list of ATA or SCSI devices for the DEVICESCAN directive of | |
164 | // smartd. Returns number N of devices, or -1 if out of | |
165 | // memory. Allocates N+1 arrays: one of N pointers (devlist); the | |
166 | // other N arrays each contain null-terminated character strings. In | |
167 | // the case N==0, no arrays are allocated because the array of 0 | |
168 | // pointers has zero length, equivalent to calling malloc(0). | |
169 | int make_device_names (char*** devlist, const char* name) { | |
170 | ARGUSED(devlist); | |
171 | ARGUSED(name); | |
172 | unsupported(); | |
173 | return 0; | |
174 | } | |
175 | ||
176 | // Like open(). Return non-negative integer handle, only used by the | |
177 | // functions below. type=="ATA" or "SCSI". If you need to store | |
178 | // extra information about your devices, create a private internal | |
179 | // array within this file (see os_freebsd.c for an example). If you | |
180 | // can not open the device (permission denied, does not exist, etc) | |
181 | // set errno as open() does and return <0. | |
182 | int deviceopen(const char *pathname, char *type){ | |
183 | ARGUSED(pathname); | |
184 | ARGUSED(type); | |
185 | unsupported(); | |
186 | return -1; | |
187 | } | |
188 | ||
189 | // Like close(). Acts only on integer handles returned by | |
190 | // deviceopen() above. | |
191 | int deviceclose(int fd){ | |
192 | ARGUSED(fd); | |
193 | unsupported(); | |
194 | return 0; | |
195 | } | |
196 | ||
197 | // Interface to ATA devices. See os_linux.c for the cannonical example. | |
198 | // DETAILED DESCRIPTION OF ARGUMENTS | |
199 | // device: is the integer handle provided by deviceopen() | |
200 | // command: defines the different operations, see atacmds.h | |
201 | // select: additional input data IF NEEDED (which log, which type of | |
202 | // self-test). | |
203 | // data: location to write output data, IF NEEDED (1 or 512 bytes). | |
204 | // Note: not all commands use all arguments. | |
205 | // RETURN VALUES (for all commands BUT command==STATUS_CHECK) | |
206 | // -1 if the command failed | |
207 | // 0 if the command succeeded, | |
208 | // RETURN VALUES if command==STATUS_CHECK | |
209 | // -1 if the command failed OR the disk SMART status can't be determined | |
210 | // 0 if the command succeeded and disk SMART status is "OK" | |
211 | // 1 if the command succeeded and disk SMART status is "FAILING" | |
212 | int ata_command_interface(int fd, smart_command_set command, int select, char *data){ | |
213 | ARGUSED(fd); | |
214 | ARGUSED(command); | |
215 | ARGUSED(select); | |
216 | ARGUSED(data); | |
217 | unsupported(); | |
218 | return -1; | |
219 | } | |
220 | ||
221 | int marvell_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 | // Interface to ATA devices behind 3ware escalade/apache RAID | |
231 | // controller cards. Same description as ata_command_interface() | |
232 | // above except that 0 <= disknum <= 15 specifies the ATA disk | |
233 | // attached to the controller, and controller_type specifies the | |
234 | // precise type of 3ware controller. See os_linux.c | |
235 | int escalade_command_interface(int fd, int disknum, int controller_type, smart_command_set command, int select, char *data){ | |
236 | ARGUSED(fd); | |
237 | ARGUSED(disknum); | |
238 | ARGUSED(controller_type); | |
239 | ARGUSED(command); | |
240 | ARGUSED(select); | |
241 | ARGUSED(data); | |
242 | ||
243 | unsupported(); | |
244 | return -1; | |
245 | } | |
246 | ||
247 | #include <errno.h> | |
248 | // Interface to SCSI devices. See os_linux.c | |
249 | int do_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report) { | |
250 | ARGUSED(fd); | |
251 | ARGUSED(iop); | |
252 | ARGUSED(report); | |
253 | unsupported(); | |
254 | return -ENOSYS; | |
255 | } |