diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index b942461..e1a75ce 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c | |||
@@ -46,8 +46,29 @@ void print_usage (void); | |||
46 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
47 | #include <sys/ioctl.h> | 47 | #include <sys/ioctl.h> |
48 | #include <fcntl.h> | 48 | #include <fcntl.h> |
49 | #ifdef linux | ||
49 | #include <linux/hdreg.h> | 50 | #include <linux/hdreg.h> |
50 | #include <linux/types.h> | 51 | #include <linux/types.h> |
52 | |||
53 | #define OPEN_MODE O_RDONLY | ||
54 | #endif /* linux */ | ||
55 | #ifdef __NetBSD__ | ||
56 | #include <sys/device.h> | ||
57 | #include <sys/param.h> | ||
58 | #include <sys/sysctl.h> | ||
59 | #include <sys/videoio.h> /* for __u8 and friends */ | ||
60 | #include <sys/scsiio.h> | ||
61 | #include <sys/ataio.h> | ||
62 | #include <dev/ata/atareg.h> | ||
63 | #include <dev/ic/wdcreg.h> | ||
64 | |||
65 | #define SMART_ENABLE WDSM_ENABLE_OPS | ||
66 | #define SMART_DISABLE WDSM_DISABLE_OPS | ||
67 | #define SMART_IMMEDIATE_OFFLINE WDSM_EXEC_OFFL_IMM | ||
68 | #define SMART_AUTO_OFFLINE 0xdb /* undefined in NetBSD headers */ | ||
69 | |||
70 | #define OPEN_MODE O_RDWR | ||
71 | #endif /* __NetBSD__ */ | ||
51 | #include <errno.h> | 72 | #include <errno.h> |
52 | 73 | ||
53 | #define NR_ATTRIBUTES 30 | 74 | #define NR_ATTRIBUTES 30 |
@@ -223,7 +244,7 @@ main (int argc, char *argv[]) | |||
223 | return STATE_OK; | 244 | return STATE_OK; |
224 | } | 245 | } |
225 | 246 | ||
226 | fd = open (device, O_RDONLY); | 247 | fd = open (device, OPEN_MODE); |
227 | 248 | ||
228 | if (fd < 0) { | 249 | if (fd < 0) { |
229 | printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); | 250 | printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); |
@@ -284,6 +305,7 @@ get_offline_text (int status) | |||
284 | int | 305 | int |
285 | smart_read_values (int fd, values_t * values) | 306 | smart_read_values (int fd, values_t * values) |
286 | { | 307 | { |
308 | #ifdef linux | ||
287 | int e; | 309 | int e; |
288 | __u8 args[4 + 512]; | 310 | __u8 args[4 + 512]; |
289 | args[0] = WIN_SMART; | 311 | args[0] = WIN_SMART; |
@@ -296,6 +318,35 @@ smart_read_values (int fd, values_t * values) | |||
296 | return e; | 318 | return e; |
297 | } | 319 | } |
298 | memcpy (values, args + 4, 512); | 320 | memcpy (values, args + 4, 512); |
321 | #endif /* linux */ | ||
322 | #ifdef __NetBSD__ | ||
323 | struct atareq req; | ||
324 | unsigned char inbuf[DEV_BSIZE]; | ||
325 | |||
326 | memset(&req, 0, sizeof(req)); | ||
327 | req.timeout = 1000; | ||
328 | memset(&inbuf, 0, sizeof(inbuf)); | ||
329 | |||
330 | req.flags = ATACMD_READ; | ||
331 | req.features = WDSM_RD_DATA; | ||
332 | req.command = WDCC_SMART; | ||
333 | req.databuf = (char *)inbuf; | ||
334 | req.datalen = sizeof(inbuf); | ||
335 | req.cylinder = WDSMART_CYL; | ||
336 | |||
337 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
338 | if (req.retsts != ATACMD_OK) | ||
339 | errno = ENODEV; | ||
340 | } | ||
341 | |||
342 | if (errno != 0) { | ||
343 | int e = errno; | ||
344 | printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); | ||
345 | return e; | ||
346 | } | ||
347 | |||
348 | (void)memcpy(values, inbuf, 512); | ||
349 | #endif /* __NetBSD__ */ | ||
299 | return 0; | 350 | return 0; |
300 | } | 351 | } |
301 | 352 | ||
@@ -439,6 +490,7 @@ int | |||
439 | smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | 490 | smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) |
440 | { | 491 | { |
441 | int e = 0; | 492 | int e = 0; |
493 | #ifdef linux | ||
442 | __u8 args[4]; | 494 | __u8 args[4]; |
443 | args[0] = WIN_SMART; | 495 | args[0] = WIN_SMART; |
444 | args[1] = val0; | 496 | args[1] = val0; |
@@ -450,6 +502,31 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | |||
450 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); | 502 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); |
451 | } | 503 | } |
452 | } | 504 | } |
505 | #endif /* linux */ | ||
506 | #ifdef __NetBSD__ | ||
507 | struct atareq req; | ||
508 | |||
509 | memset(&req, 0, sizeof(req)); | ||
510 | req.timeout = 1000; | ||
511 | req.flags = ATACMD_READREG; | ||
512 | req.features = smart_command[command].value; | ||
513 | req.command = WDCC_SMART; | ||
514 | req.cylinder = WDSMART_CYL; | ||
515 | req.sec_count = val0; | ||
516 | |||
517 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
518 | if (req.retsts != ATACMD_OK) | ||
519 | errno = ENODEV; | ||
520 | if (req.cylinder != WDSMART_CYL) | ||
521 | errno = ENODEV; | ||
522 | } | ||
523 | |||
524 | if (errno != 0) { | ||
525 | e = errno; | ||
526 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); | ||
527 | return e; | ||
528 | } | ||
529 | #endif /* __NetBSD__ */ | ||
453 | return e; | 530 | return e; |
454 | } | 531 | } |
455 | 532 | ||
@@ -458,6 +535,7 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | |||
458 | int | 535 | int |
459 | smart_read_thresholds (int fd, thresholds_t * thresholds) | 536 | smart_read_thresholds (int fd, thresholds_t * thresholds) |
460 | { | 537 | { |
538 | #ifdef linux | ||
461 | int e; | 539 | int e; |
462 | __u8 args[4 + 512]; | 540 | __u8 args[4 + 512]; |
463 | args[0] = WIN_SMART; | 541 | args[0] = WIN_SMART; |
@@ -470,6 +548,35 @@ smart_read_thresholds (int fd, thresholds_t * thresholds) | |||
470 | return e; | 548 | return e; |
471 | } | 549 | } |
472 | memcpy (thresholds, args + 4, 512); | 550 | memcpy (thresholds, args + 4, 512); |
551 | #endif /* linux */ | ||
552 | #ifdef __NetBSD__ | ||
553 | struct atareq req; | ||
554 | unsigned char inbuf[DEV_BSIZE]; | ||
555 | |||
556 | memset(&req, 0, sizeof(req)); | ||
557 | req.timeout = 1000; | ||
558 | memset(&inbuf, 0, sizeof(inbuf)); | ||
559 | |||
560 | req.flags = ATACMD_READ; | ||
561 | req.features = WDSM_RD_THRESHOLDS; | ||
562 | req.command = WDCC_SMART; | ||
563 | req.databuf = (char *)inbuf; | ||
564 | req.datalen = sizeof(inbuf); | ||
565 | req.cylinder = WDSMART_CYL; | ||
566 | |||
567 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
568 | if (req.retsts != ATACMD_OK) | ||
569 | errno = ENODEV; | ||
570 | } | ||
571 | |||
572 | if (errno != 0) { | ||
573 | int e = errno; | ||
574 | printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); | ||
575 | return e; | ||
576 | } | ||
577 | |||
578 | (void)memcpy(thresholds, inbuf, 512); | ||
579 | #endif /* __NetBSD__ */ | ||
473 | return 0; | 580 | return 0; |
474 | } | 581 | } |
475 | 582 | ||